sql - mysql select where in -
i have sub-query works perfectly:
select group_concat(zone separator ', ') typeofru id in (5,7) /*this works good*/
the problem have 5 , 7 on varchar column ('5,7') , cannot make works
select group_concat(zone separator ', ') typeofru id in ('5,7') /*this not working */
how can cast ('5,7') value type in order make works
the final query need use this, not seems work:
select name, (select group_concat(zone separator ', ') typeofru id in (typeofru_ids)) deviceru device_id=5
use find_in_set()
where find_in_set(id, '5,7') > 0
returns value in range of 1 n if string str in string list strlist consisting of n substrings. string list string composed of substrings separated “,” characters. if first argument constant string , second column of type set, the find_in_set() function optimized use bit arithmetic. returns 0 if str not in strlist or if strlist empty string. returns null if either argument null. function not work if first argument contains comma (“,”) character.
as lesson learned, not store values separated comma.
in case there spaces before , after comma, need replace space first,
where find_in_set(id, replace(' 5 , 7', ' ','')) > 0
Comments
Post a Comment