/*
drop table if exists hobby_users;
create table hobby_users(hobby_users_id int, user_name varchar(3), user_subcategory_id varchar(3));
drop table if exists subcategory_master;
create table subcategory_master(subcategory_master_id int, subcategory_name varchar(3));
insert into hobby_users values
(1,'abc','1,2'),
(2,'def','1,3');
insert into subcategory_master values
(1,'aaa'),(2,'bbb'),(3,'ccc'),(4,'ddd');
*/
MariaDB [sandbox]> SELECT h.hobby_users_id,
-> h.user_subcategory_id
-> ,GROUP_CONCAT(sm.subcategory_name) AS subcategory_name
-> FROM `hobby_users` h
-> INNER JOIN subcategory_master sm
-> WHERE h.hobby_users_id='1'
-> AND
-> find_in_set(sm.subcategory_master_id,h.user_subcategory_id) > 0
-> GROUP BY h.user_subcategory_id;
+----------------+---------------------+------------------+
| hobby_users_id | user_subcategory_id | subcategory_name |
+----------------+---------------------+------------------+
| 1 | 1,2 | aaa,bbb |
+----------------+---------------------+------------------+
1 row in set (0.00 sec)
如果它不是爲時已晚,你應該認真考慮您的架構,特別是'user_subcategory_id'列。如果爲時已晚,請查看['FIND_IN_SET()'](https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set)。 – shmosel