MySQL - How to select rows where value is in array?

前端 未结 4 716
北海茫月
北海茫月 2020-12-07 22:20

Ok, normally I know you would do something like this if you knew the array values (1,2,3 in this case):

SELECT * WHERE id IN (1,2,3)

But I

4条回答
  •  抹茶落季
    2020-12-07 23:04

    If you use the FIND_IN_SET function:

    FIND_IN_SET(a, columnname) yields all the records that have "a" in them, alone or with others

    AND

    FIND_IN_SET(columnname, a) yields only the records that have "a" in them alone, NOT the ones with the others

    So if record1 is (a,b,c) and record2 is (a)

    FIND_IN_SET(columnname, a) yields only record2 whereas FIND_IN_SET(a, columnname) yields both records.

提交回复
热议问题