I need to retrieve ONE row for every source id that has the lowest date coinciding with each id number.
source table:
id# sourceID Date
1 a1 2-3-02
2 c4 3-7-01
2 d3 4-12-98
3 5f 6-3-95
4 d5 5-22-02
4 2w 3-11-97
4 3v 1-15-01
5 3a 2-17-03
desired result:
id# sourceID Date
1 a1 2-3-02
2 d3 4-12-98
3 5f 6-3-95
4 2w 3-11-97
5 3a 2-17-03
I tried min() on date column omitting sourceID I get the right rows but I need the sourceID too and if I add in I get all of them not just the ones with the min(date) with distinct also.
close as I can get but no good:
select distinct id#, sourceID, min(date)
from source table,
group by id#, sourceID
order by id#
source table:
id# sourceID Date
1 a1 2-3-02
2 c4 3-7-01
2 d3 4-12-98
3 5f 6-3-95
4 d5 5-22-02
4 2w 3-11-97
4 3v 1-15-01
5 3a 2-17-03
desired result:
id# sourceID Date
1 a1 2-3-02
2 d3 4-12-98
3 5f 6-3-95
4 2w 3-11-97
5 3a 2-17-03
I tried min() on date column omitting sourceID I get the right rows but I need the sourceID too and if I add in I get all of them not just the ones with the min(date) with distinct also.
close as I can get but no good:
select distinct id#, sourceID, min(date)
from source table,
group by id#, sourceID
order by id#