Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> how to select distinct records
i have a table like one shown below
start_date | end_date | traveller
1/1/2005 | 10/10/2005 | a 1/1/2005 | 10/10/2005 | b 5/1/2005 | 11/10/2005 | c 2/1/2005 | 6/11/2005 | d 3/1/2005 | 11/23/2005 | e 3/1/2005 | 11/23/2005 | f
I need to write a query that would give me only one record for any distinct date range. My results should be something like
select distinct start_date, end_date, (first traveller found for that start_date and end_date) from table;
start_date | end_date | traveller
1/1/2005 | 10/10/2005 | a 5/1/2005 | 11/10/2005 | c 2/1/2005 | 6/11/2005 | d 3/1/2005 | 11/23/2005 | e
or
start_date | end_date | traveller
1/1/2005 | 10/10/2005 | b 5/1/2005 | 11/10/2005 | c 2/1/2005 | 6/11/2005 | d 3/1/2005 | 11/23/2005 | f
As you see I dont care about which traveller is returned for a particular date range (1/1/2005 - 10/10/2005) if it returns 'a' or 'b'. All i need is one record per date range.
I know I can write a function that takes the start and end_date as parameters and returns the first record found by using the rownum, but is there a way to do this in plain SQL ?
Thanks in advance,
Wally
Received on Thu Nov 10 2005 - 19:18:29 CST
![]() |
![]() |