MySql : Select statement using IN operator

后端 未结 3 490
醉梦人生
醉梦人生 2021-01-16 07:40

I have a table with several fields and one field having 3 Comma Separated Values

 Column 1 Column 2 
    1        1,2,3
    2        2,3,4
    3        6,7,8         


        
相关标签:
3条回答
  • 2021-01-16 08:11

    You can use FIND_IN_SET():

    SELECT column1 FROM table WHERE FIND_IN_SET('2', column2) != 0
    

    The IN operator is basically a shortcut for lots of ORs:

    WHERE column2 = IN ('a', 'b', 'c')
    

    gives the same result as

    WHERE (column2 = 'a' OR column2 = 'b' OR column2 = 'c')
    
    0 讨论(0)
  • 2021-01-16 08:30

    If I have understood your question correctly then how about trying - select Column1, Column2 from Table where Column1 <=

    cheers

    0 讨论(0)
  • 2021-01-16 08:34

    You should be able to use Like to do this, something like:

    SELECT * FROM tablename WHERE [Column 2] LIKE ("%2%");
    
    0 讨论(0)
提交回复
热议问题