marchemike
marchemike

Reputation: 3277

Getting the lowest record for Oracle

I'm having a problem with selecting data from my table, where in I'm trying to select a group of records that have some fields with duplicate values, I want to select the ones with the lowest value, however since I'm fairly new to SQL, I'm at a dead end right now on what syntax should I use to get only the lowest values.

Example

SEQ_NO     ID_NO     
01          1990
02          1990
03          1991
05          1890
08          1890
01          1992

I only want to select all the records with low SEQ_NO, so I should get all of the records from 1990 to 1992, but only each ID_NO has only the lowest SEQ_NO.

What syntax should I use to remove the unnecessary records (for example, remove the SEQ_NO for 1990)?

Upvotes: 2

Views: 123

Answers (1)

John Woo
John Woo

Reputation: 263693

use MIN, which is an AGGREGATE FUNCTION and a GROUP BY clause.

SELECT  ID_NO, MIN(SEQ_NO) LowestVALUE
FROM    Table1
WHERE   ID_NO BETWEEN 1990 AND 1992
GROUP   BY ID_NO

Upvotes: 2

Related Questions