SQLite string contains other string query

前端 未结 2 410
小蘑菇
小蘑菇 2020-12-04 08:56

How do I do this?

For example, if my column is \"cats,dogs,birds\" and I want to get any rows where column contains cats?

相关标签:
2条回答
  • 2020-12-04 09:32

    While LIKE is suitable for this case, a more general purpose solution is to use instr, which doesn't require characters in the search string to be escaped. Note: instr is available starting from Sqlite 3.7.15.

    SELECT *
      FROM TABLE  
     WHERE instr(column, 'cats') > 0;
    

    Also, keep in mind that LIKE is case-insensitive, whereas instr is case-sensitive.

    0 讨论(0)
  • 2020-12-04 09:33

    Using LIKE:

    SELECT *
      FROM TABLE
     WHERE column LIKE '%cats%'  --case-insensitive
    
    0 讨论(0)
提交回复
热议问题