Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple OR Clauses in MySQL

Tags:

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 query?

$sql = "SELECT name FROM artists WHERE (id=3 OR id=9 OR .... id-100)" 
like image 853
Grant Avatar asked Jun 13 '10 02:06

Grant


People also ask

Can I use multiple in MySQL?

It is possible to use a different MySQL server binary per instance, or use the same binary for multiple instances, or any combination of the two approaches.

Can I use multiple WHERE in SQL?

You can specify multiple conditions in a single WHERE clause to, say, retrieve rows based on the values in multiple columns. You can use the AND and OR operators to combine two or more conditions into a compound condition.

How do I select multiple records in MySQL?

To select multiple values, you can use where clause with OR and IN operator.

How do I run multiple SQL statements in MySQL?

MySQL also supports the execution of a string containing multiple statements separated by semicolon ( ; ) characters. This capability is enabled by special options that are specified either when you connect to the server with mysql_real_connect() or after connecting by calling mysql_set_server_option() .


1 Answers

  .... WHERE id IN (3, 9, 100, ...) 
like image 106
Ignacio Vazquez-Abrams Avatar answered Sep 27 '22 16:09

Ignacio Vazquez-Abrams