Home » SQL & PL/SQL » SQL & PL/SQL » How to merge 2 rows from a table to 1 row (2 columns)
How to merge 2 rows from a table to 1 row (2 columns) [message #672244] Mon, 08 October 2018 04:54 Go to next message
dsslim
Messages: 4
Registered: March 2018
Junior Member
Hi,

I have a table below with 6 rows. And I like the end result to be like this:

ID TYPE PRIORITY
001 Tennis P3-P1
002 Gym P2-P3
003 Soccer P1-P2

May I know how do I achieve this ? TIA !


Source DDL:

CREATE TABLE TAB1
( "ID" VARCHAR2(4 BYTE),
"TYPE" VARCHAR2(7 BYTE),
"PRIORITY" VARCHAR2(10 BYTE)
) ;


Insert into TAB1 (ID,TYPE,PRIORITY) values ('0001',null,'P3-P1');
Insert into TAB1 (ID,TYPE,PRIORITY) values ('0001','Tennis',null);
Insert into TAB1 (ID,TYPE,PRIORITY) values ('0002',null,'P2-P3');
Insert into TAB1 (ID,TYPE,PRIORITY) values ('0002','Gym',null);
Insert into TAB1 (ID,TYPE,PRIORITY) values ('0003','Soccer',null);
Insert into TAB1 (ID,TYPE,PRIORITY) values ('0003',null,'P1-P2');
Re: How to merge 2 rows from a table to 1 row (2 columns) [message #672245 is a reply to message #672244] Mon, 08 October 2018 05:51 Go to previous messageGo to next message
Michel Cadot
Messages: 66475
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals, as solution depends on it.
In the end, if you want to continue to get help, feedback in your topics.

SQL> select id, max(type) type, max(priority) priority from tab1 group by id;
ID   TYPE    PRIORITY
---- ------- ----------
0001 Tennis  P3-P1
0002 Gym     P2-P3
0003 Soccer  P1-P2

Re: How to merge 2 rows from a table to 1 row (2 columns) [message #672250 is a reply to message #672245] Mon, 08 October 2018 20:58 Go to previous message
dsslim
Messages: 4
Registered: March 2018
Junior Member
Thanks very much !
Previous Topic: HELP NEEDED IN COMPILING PACKAGE
Next Topic: Help required on assigning value to Tabletype variable!
Goto Forum:
  


Current Time: Tue Jul 23 12:54:21 CDT 2019