Home » SQL & PL/SQL » SQL & PL/SQL » Joining 2 rows into 1
Joining 2 rows into 1 [message #194439] Fri, 22 September 2006 04:26 Go to next message
Messages: 110
Registered: March 2006
Senior Member
My query returns 2 rows, in my 4 column output, first 3 columns have same values in both the rows. only last column is diiffrent. Now I need to get outout in one row. that is the 4th column which is diffrent should be displayed next to 3rd column

col1 col2 col3 col4
val1 val2 val3 val4
val1 val2 val3 val5

It shud print

val1 val2 val3 val4 val5

Thanks in advance

icon2.gif  Re: Joining 2 rows into 1 [message #194460 is a reply to message #194439] Fri, 22 September 2006 05:31 Go to previous messageGo to next message
Messages: 252
Registered: April 2001
Location: Chennai
Senior Member
clarity is always of great help and if you could post the scripts along with your so called query we would be able to figure out what you require.
Re: Joining 2 rows into 1 [message #194578 is a reply to message #194439] Fri, 22 September 2006 15:37 Go to previous message
Messages: 18
Registered: September 2006
Location: London
Junior Member
if it's always just 2 values (i.e. you will not need other distinct col4 values to be displayed as col6, col7 etc), and values in col4 can be ordered, try something like this:

select col1, col2, col3, min(col4) as col4, max(col4) as col5
from my_table_name
group by col1, col2, col3

If you would like to display more than 2 values, then aggregate all values for col4 in that column (for example, build a comma separated list of col4 values). This page should give you some hints how to do that:


Gojko Adzic
Previous Topic: Commit in autonomous transaction
Next Topic: complicated distinct query
Goto Forum:

Current Time: Fri Oct 28 10:00:10 CDT 2016

Total time taken to generate the page: 0.07039 seconds