I have the following table:
... | parents_id | ...
________________________
... | 1, 40, 7 | ...
... | 10, 4, 7, 1 | ...
... | 45, 40, 1, 7 | ...
... | other_rows | ...
Now, I need to get these three rows, I use this query SELECT * FROM products WHERE FIND_IN_SET(1, parents_id) > 0
, but I only get the first row ( 1, 40, 7
), any help?
As per documentation - FIND_IN_SET
's second argument is a comma separated list. So the value 10, 4, 7, 1
being split by a comma becomes to the following 4 values:
10
4
- space followed by 4 7
- space followed by 7 1
- space followed by 1 None of them equal to 1
Solution: stop using this approach and normalize your schema to use one-to-many (or many-to-many).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.