Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to select rows with min value on a specific column

1024177Jul 10 2013 — edited Jul 11 2013

I have a query:

select

  m.x1,

  round (to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') - m.x2, 0) as numofdays

from

  table1 m,

  table2 l

where

  l.x3 = m.x3 and

  to_date (l.y1, 'mm/dd/yyyy HH:MI:SS AM') >= TO_DATE('01012013','MMDDYYYY') and

  ...;

and I got this result table:

x1 (ID)numofdays
0015

001

10
0022
0033
0031
0040
00566
......

several ID's have multiple values on the second column, I want to have only distinct IDs with smallest "numofdays" like this:

x1 (ID)numofdays
0015
0022
0031
0040
00566
......

Any ideas?

This post has been answered by Frank Kulash on Jul 10 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2013
Added on Jul 10 2013
7 comments
3,117 views