Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL OR in query

Tags:

php

mysql

Can I use "OR" in a mysql statement to check a fields value against multiple options?

    //THE QUESTION IF HAVE IS HOW DO I DO SOMETHING LIKE BELOW  MAINLY THE "1 OR 2 OR 3 OR 4" PART.

    $sql = "SELECT email FROM USER_INFO WHERE storeID = '$storeNUM' AND region = '1 OR 2 OR 3 OR 4'";
   $results2 = $db->query($sql);
like image 420
Denoteone Avatar asked Feb 22 '26 23:02

Denoteone


1 Answers

You can use IN as a shorthand for multiple OR tests.

SELECT email
    FROM USER_INFO
    WHERE storeID = '$storeNUM'
        AND region IN (1,2,3,4);
like image 55
Joe Stefanelli Avatar answered Feb 25 '26 13:02

Joe Stefanelli