mysql | Request from empty column and FIND_IN_SET

前端 未结 1 509
甜味超标
甜味超标 2021-01-28 04:19

I have a table:

id  name   position   status
1   A      1,2        1
2   B      1          1
3   C                 1
4   D      2          1

Wh

相关标签:
1条回答
  • 2021-01-28 04:43

    you dont need to check if position is empty while you checking numbers in field list .

    you dont need to check position = FIND_IN_SET.... . it will return the value where 1 is in position.

    you need to do it like that:

     SELECT `id` 
     FROM  `table` 
     WHERE `status`=1
     AND  FIND_IN_SET( 1,  `position` ) 
     OR   FIND_IN_SET( 2,  `position` ) 
    

    DEMO HERE

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