php - concat group a SELECT in another SELECT -
simple question:
there 2 tables:
genre [name,songid]
song [id,title,userid,status]
select id,name,title,userid,status songs inner join genre on song.id=genre.songid order id asc;
what query result from
+----+-------------+----------------------+--------+--------+ | id | genre.name | song.title | userid | status | +----+-------------+----------------------+--------+--------+ | 1 | tech | feel | 1 | 1 | | 2 | tech | tester | 1 | 1 | | 3 | music | sejujurnya | 1 | 1 | | 4 | music | not done | 1 | 1 | | 5 | life | cinta | 1 | 1 | | 6 | life | feel | 1 | 1 | | 7 | life | not done | 1 | 1 | | 8 | truth | tester | 1 | 1 | | 9 | tree | tester | 1 | 1 | | 10 | climb | tester | 1 | 1 | +----+-------------+----------------------+--------+--------+
to
+----+-------------+---------------------------------+--------+--------+ | id | genre.name | song.title | userid | status | +----+-------------+---------------------------------+--------+--------+ | 1 | tech | feel all,tester | 1 | 1 | | 2 | music | sejujurnya, not done | 1 | 1 | | 3 | life | cinta, feel all, note done | 1 | 1 | | 4 | truth | tester | 1 | 1 | | 5 | tree | tester | 1 | 1 | | 6 | climb | tester | 1 | 1 | +----+-------------+---------------------------------+--------+--------+
thanks
use group_concat group by
select id, genre.name, group_concat(title) title, userid, status songs inner join genre on song.id=genre.songid group genre.name order id asc
Comments
Post a Comment