Query with multiple values in a column

后端 未结 4 1305
忘了有多久
忘了有多久 2020-11-22 03:14

I have a table like:

id     name            children
1      Roberto         Michael,Dia
2      Maria           John,Alex
3      Mary            Alexandre,Dia         


        
4条回答
  •  执念已碎
    2020-11-22 03:31

    The best solution would be to normalize your schema. You should have a separate table with one row for each child, instead of a comma-delimited list. Then you can join with this table to find parent with a specific child. See @themite's answer for an example of this.

    But if you can't do that for some reason, you can use FIND_IN_SET:

    WHERE FIND_IN_SET('Alex', children)
    

提交回复
热议问题