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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using multiples queries

Status
Not open for further replies.

moonfish07

Programmer
Dec 1, 2002
2
SG
SELECT *, (SELECT COUNT(*) FROM PHOTOPICTURES a,PHOTOCATEGORIES b WHERE a.PIC_CAT = b.CAT_ID) AS PIC_COUNT FROM PHOTOCATEGORIES ORDER BY CAT_NAME
can any1 tell me what's wrong with the above query as

SELECT *, (1) AS PIC_COUNT FROM PHOTOCATEGORIES ORDER BY CAT_NAME <----this gives a result
 
thanks for replying....
do u know of any method to make it into a single query
 
Assuming from your query that you're trying to get the number of pictures for each category, this is what I would try:

SELECT c.*, COUNT (p.PIC_ID) AS PIC_COUNT
FROM PHOTOCATEGORIES c
LEFT JOIN PHOTOPICTURES p ON p.PIC_CAT = c.CAT_ID
GROUP BY c.CAT_ID

Hope this helps,

Brommrrrr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top