Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery with many results?? 1

Status
Not open for further replies.

sera

Technical User
Jun 29, 2000
360
US
So i'm looking for a way to have a query with a subquery, but the subquery returns more than one item.

ex.
SELECT * FROM menu where parent_id = (SELECT menu_id FROM menu WHERE parent_id = 0)

the subquery will return [22,30,33]
I would like the top query to execute logically as follows:

SELECT * FROM menu where parent_id = 22 OR parent_id = 30 OR parent_id = 33

I can't predict the count of the subquery.

I can do this with loops in my php but I have a feeling that it is possible to do this with a single SQL statement (multi subqueries).

Does anyone have any ideas???



Sera
 
instead of this --

where parent_id = (SELECT ...

use this --

where parent_id IN (SELECT ...

r937.com | rudy.ca
 
that was too freaking easy! thanks


Sera
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top