MySQL FIND_IN_SET() not working as expected

后端 未结 1 1368
我在风中等你
我在风中等你 2021-01-15 06:04

I have the following table:

... | parents_id   | ...
________________________
... | 1, 40, 7     | ...
... | 10, 4, 7, 1  | ...
... | 45, 40, 1, 7 | ...
...          


        
相关标签:
1条回答
  • 2021-01-15 06:29

    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:

    1. 10
    2. 4 - space followed by 4
    3. 7 - space followed by 7
    4. 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).

    0 讨论(0)
提交回复
热议问题