iSee Dev iSee Dev - 2 months ago 9
MySQL Question

SELECT all rows by one field and different values

Please help me with this SQL Query.

I have a table "

objects
". In that table exist field agent. On web site my agent
ID
is "7".

also I have array with ID's of other agents.

I want to make one SQL query to SELECT all objects FROM objects WHERE agent=7 and also I want to select objects where agent = 4, 5, 8, 9 (id's 4 5 8 9 exist in my array "
IDs
")

NOW I have
SELECT * FROM objects WHERE agent=7 AND status='$st' ORDER BY ID DESC
but it select only my objects, I need include in this request another objects of another agents by their ids

Answer

You can use IN clause to fetch all the objects

SELECT * FROM objects WHERE agent IN ('4', '5', '7','8','9') 
AND status='$st' ORDER BY id DESC
Comments