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!

How to rewrite a sub-query

Status
Not open for further replies.

lonestarbill

Programmer
Sep 10, 2002
2
US
I use this query against an Access database and need to convert it to MySQL. It just does a quick count of active products in each category, and it seems overkill to create temp tables to do this. Is there a way to re-write this using joins? I'm not very experienced with SQL, and everything I've tried hasn't worked out. Thanks!

SELECT count(idProd) as CountCatItems FROM cat_prod WHERE idCat=14 and (idProd in (SELECT idProd from Prods WHERE prods.active=-1))
 
try this one

SELECT COUNT(cat_prod.idProd) AS CountCatItems
FROM cat_prod INNER JOIN Prods
ON Prods.idProd = cat_prod.idProd
WHERE Prods.active=-1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top