SQL search multiple values in same field

后端 未结 4 1305
北恋
北恋 2020-11-30 04:48

I\'m building a simple search algorithm and I want to break my string with spaces, and search my database on it, like so:

$         


        
4条回答
  •  借酒劲吻你
    2020-11-30 05:21

    Yes, you can use SQL IN operator to search multiple absolute values:

    SELECT name FROM products WHERE name IN ( 'Value1', 'Value2', ... );
    

    If you want to use LIKE you will need to use OR instead:

    SELECT name FROM products WHERE name LIKE '%Value1' OR name LIKE '%Value2';
    

    Using AND (as you tried) requires ALL conditions to be true, using OR requires at least one to be true.

提交回复
热议问题