i have varchar(255) field named "user_id" in database table in store comma separated user ids 234,235.
i have 1 inner query in query below 's' table alias:
(select group_concat(concat(first_name,' ',last_name)) users user_id in (s.user_id)) user_name
now getting s.user_id value : '234,235' in result getting name of first user only. want both of users' name comma separated. (i want => ('234','235') or (234,235) works in in() function)
to use find_in_set() function not feasible query long.
storing ids in comma-separate string need reference bad design. it's better normalize data , store in ways database supports natively.
that said, need user id within string, 1 solution regular expression. this slow , think it's worth effort reorganize ids in separate table / column instead.
select group_concat(concat(first_name,' ',last_name)) users s.user_id regexp concat('(^|,)', user_id, '($|,)')
this matches id comma on either side or @ beginning or end of string.
Comments
Post a Comment