Select [message #265203] |
Wed, 05 September 2007 14:16  |
kalkumar
Messages: 8 Registered: July 2007
|
Junior Member |
|
|
Hi,
I have tables like this:
Table1:
Year | ID | col1
2007 | 1 | x
Table2:
Year | ID | Date
2007 | 1 | 09/2/2007
2007 | 1 | 09/1/2006
Now I need to get the result like this in one row:
Year | ID | Date1 | Date2
2007 | 1 | 09/2/2007 | 09/1/2006
For each year there are two different dates only so I need Date1 and Date2 only.
How to get the result from two rows into one row.
Thanks in advance
|
|
|
Re: Select [message #265207 is a reply to message #265203] |
Wed, 05 September 2007 14:28   |
skooman
Messages: 913 Registered: March 2005 Location: Netherlands
|
Senior Member |
|
|
If you are 100% sure there are only two dates per year, you could do something like:
SQL> SELECT t.year_col
2 ,t.id_col
3 ,MIN(t.date_col)
4 ,MAX(t.date_col)
5 FROM table2 t
6 GROUP BY t.year_col
7 ,t.id_col;
YEAR_COL ID_COL MIN(T.DATE_COL) MAX(T.DATE_COL)
---------- ---------- --------------- ---------------
2007 1 9-1-2006 9-2-2007 (reverse the order of columns if you like).
If in real life: try to avoid reserved words like year, id and date as column names... That's why I have renamed your columns in this example.
|
|
|
|
|
|
|
|