Mysql WHERE problem with comma-separated list

前端 未结 3 992
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 19:48

I need help for this problem.

In MYSQL Table i have a field :

Field  : artist_list  
Values : 1,5,3,401

I need to find all records

3条回答
  •  自闭症患者
    2020-12-11 20:30

    Your database organization is a problem; you need to normalize it. Rather than having one row with a comma-separated list of values, you should do one value per row:

    uid    artist
    1      401
    1       11
    1        5
    2        5
    2        4
    2        2
    

    Then you can query:

    SELECT uid
      FROM table
     WHERE artist = 401
    

    You should also look into database normalization because what you have is just going to cause more and more problems in the future.

提交回复
热议问题