SELECT
memId, GROUP_CONCAT(courId)
FROM table_name
GROUP BY memId
Let assuming you have created you table like shown below
CREATE TABLE test (
MemId INTEGER,
CourId VARCHAR (50)
);
and executing insert like shown below
INSERT INTO test VALUES (1, '2');
INSERT INTO test VALUES (1, '3');
INSERT INTO test VALUES (2, '2');
INSERT INTO test VALUES (3, '1');
INSERT INTO test VALUES (3, '3');
Run query like so
SELECT MemId, GROUP_CONCAT( CourId) FROM test GROUP BY MemId
Your result should look like this
| MemId | GROUP_CONCAT( CourId) |
|-------|-----------------------|
| 1 | 2,3 |
| 2 | 2 |
| 3 | 1,3 |
for further reading and understanding see this link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.