Mert Zaim Mert Zaim - 6 months ago 16
PHP Question

Multiple where clauses in one mysql query

I want to get all results which these queries give with one query;

1- $query = mysql_query("select * from table where view='1'");
2- $query = mysql_query("select * from table where view='2'");
3- $query = mysql_query("select * from table where view='3'");
4- $query = mysql_query("select * from table where view='4'");
.
.
.
999999- $query = mysql_query("select * from table where view='999999'");


How can I do that easily?

Answer

Several ways. For this extreme case (or any range) use BETWEEN:

SELECT * FROM table WHERE view BETWEEN 1 AND 999999

If not a range use IN:

SELECT * FROM table WHERE view IN (1,2,3,4,999999)