Multiple OR Clauses in MySQL

后端 未结 7 1450
陌清茗
陌清茗 2020-12-06 05:22

I\'m trying to grab content where id = 3 OR id = 9 OR id = 100... Keep in mind, I can have a few hundred of these ids.

What is the most efficient way to write my q

相关标签:
7条回答
  • 2020-12-06 05:34
    SELECT * FROM table WHERE id IN (1, 2, 3 etc)
    

    And call only the columns you need rather than using *!

    0 讨论(0)
  • 2020-12-06 05:40

    You may want to use the IN() function:

    ... WHERE id IN (3, 9, 100);
    

    The IN() function syntax:

    expr IN (value,...)

    Check whether a value is within a set of values ...

    Returns 1 if expr is equal to any of the values in the IN list, else returns 0.

    0 讨论(0)
  • 2020-12-06 05:48
      ....
    WHERE id IN (3, 9, 100, ...)
    
    0 讨论(0)
  • 2020-12-06 05:49

    $sql = "SELECT name FROM artists WHERE id REGEXP regex-pattern"

    0 讨论(0)
  • 2020-12-06 05:51

    You can use SQL IN condition

    SELECT * FROM table WHERE ID IN ('1', '2', '3', '4');
    
    0 讨论(0)
  • 2020-12-06 05:53
    SELECT * FROM table WHERE id IN (1,2,5);
    
    0 讨论(0)
提交回复
热议问题