iSee Dev iSee Dev - 1 year ago 94
MySQL Question

SELECT all rows by one field and different values

Please help me with this SQL Query.

I have a table "

". In that table exist field agent. On web site my agent
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 "

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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download