问题
Above question may be confusing so let me explain it. I have a table with structure similar as below :
form_id bank_ids
1 5,6,7,8
2 7,10
3 4,7,9
4 5,8,1
Now suppose I want to extract the form ids assigned to bank_id 7
, how can I able to extract it?
回答1:
MySQL has a builtin function for that called FIND_IN_SET.
SELECT *
FROM tableName
WHERE FIND_IN_SET('7', bank_ids) > 0
You should properly normalize your table.
UPDATE
if you want to use LIKE
, you need to concatenate ,
on both side. eg
WHERE CONCAT(',', bank_ids, ',') LIKE CONCAT('%,', '7', ',%')
来源:https://stackoverflow.com/questions/19462626/extracting-the-ids-assigned-to-a-list-of-user-ids