MySQL Forums
Forum List  »  General

Mysql Query to concat values based on Unique key
Posted by: Ozark Ram
Date: April 29, 2022 08:32AM

Hi All,

Hope you are doing well!...I am trying to to group the values in the below input table by pickno..

DDL for Input table

create table input
(pickno varchar(50),
reasonorshipinstrction varchar(1000),
code varchar(2),
username varchar(45)
insert into input values
('L11230','side cracks','R','Tuli'),
('L11230','Funnel issue','R','Tuli'),
('L11230','Back to date 02/03/2021','S','Deemra'),
('L11230','Completed date changed 03/04/2021 to 09/04/2022','S','Alex'),
('M12401','Random repair ','R','Mina'),
('M12401','returned from shop','S','Deemra'),
('M12401','this pickup is scheduled 04/2/2021','S','Tuli')

Basically I am trying to group by pickno and then group the code R into the column Reason and the code S into the column shipinstruction (combining the names and the reason or shipping instruction)..

create table output
(pickno varchar(20),
reason varchar(10000),
shipinstruction varchar(10000))

insert into output values
('L11230','name-Tuli,reason -side cracks ,name -Tuli, reason-Funnel issue','name-Deemra,shippinginstruction-Back to date 02/03/2021,name-Alex,shippinginstruction -Completed date changed 03/04/2021 to 09/04/2022'),
('M12401','name-Mina,reason-random repair,name-Alex, reason-allergen','name-Deemra,shippinginstruction- returnedfromshop,name-Tuli ,shippinginstruction -this pickup is scheduled 04/2/2021')


Options: ReplyQuote

Written By
Mysql Query to concat values based on Unique key
April 29, 2022 08:32AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.