Hello
I am looking for some help on how to combine the comments from table based on column values
select * from comments
I have select query that looks into multiple table and gives me this result
id seq_ord seq ptr comments name order_num
1111 3 0 135402231432 ok to take 3 times Tylenol 500MG TAB 22
1111 2 0 135402231433 ok to take 2 times Tylenol 500MG TAB 22
1111 1 0 135402233121 ok to take 1 time Tylenol 500MG TAB 22
1111 1 2 135402233145 Repeat 2 weeks 1 time Tylenol 500MG TAB 22
2222 3 0 135402231467 ok to take 3 times Zantac 150 MG TAB 38
2222 2 0 135402231483 ok to take 2 times Zantac 150 MG TAB 38
2222 1 0 135402233195 ok to take 1 time Zantac 150 MG TAB 38
2222 1 2 135402233155 Repeat 2 weeks 1 time Zantac 150 MG TAB 38
Need the results like. Add the comments if the id, seq,order_num,name and order_num is same
id combined comments order_num
1111 seq 1:ok to take 1 time, seq 2:ok to take 2 times, seq 3: ok to take 3 times 22
1111 Repeat 2 weeks 1 time 22
2222 seq 1:ok to take 1 time, seq 2:ok to take 2 times, seq 3: ok to take 3 times 38
2222 Repeat 2 weeks 1 time 38
create table comments(
id INT NOT NULL,
seq_ord VARCHAR(10) NOT NULL,
seq VARCHAR(10) NOT NULL,
ptr VARCHAR(25) NOT NULL,
comments varchar(max),
name varchar(40),
order_num varchar(10)
);
INSERT INTO comments
VALUES ('1111','3','0','135402231432','ok to take 3 times','Tylenol 500MG TAB','22');
INSERT INTO comments
VALUES ('1111','2','0','135402231433','ok to take 2 times','Tylenol 500MG TAB','22');
INSERT INTO comments
VALUES ('1111','1','0','135402233121','ok to take 1 time','Tylenol 500MG TAB','22');
INSERT INTO comments
VALUES ('1111','1','2','135402233145','Repeat 2 weeks 1 time','Tylenol 500MG TAB','22');
INSERT INTO comments
VALUES ('2222','3','0','135402231467','ok to take 3 times','Zantac 150 MG TAB','38');
INSERT INTO comments
VALUES ('2222','2','0','135402231483','ok to take 2 times','Zantac 150 MG TAB','38');
INSERT INTO comments
VALUES ('2222','1','0','135402233195','ok to take 1 time','Zantac 150 MG TAB','38');
INSERT INTO comments
VALUES ('2222','1','2','135402233155','Repeat 2 weeks 1 time','Zantac 150 MG TAB','38');
Thanks
Asha