filburt1
04-22-2003, 01:12 AM
I have two tables: mailmessage and mailfolder. This query works perfectly (returns the number of messages in each folder) except for when one folder doesn't have any messages.
I know I have to use a JOIN to solve this. How do I do it?
SELECT mf.mailfolderid, mf.title, COUNT(mm.mailmessageid) AS messagecount
FROM mailmessage mm, mailfolder mf
WHERE mf.mailfolderid = mm.mailfolderid
AND mf.userid = 1 AND mm.userid = 1
GROUP BY mf.mailfolderid
If you want I can give a schema for both tables but you shouldn't need it, I think.
I know I have to use a JOIN to solve this. How do I do it?
SELECT mf.mailfolderid, mf.title, COUNT(mm.mailmessageid) AS messagecount
FROM mailmessage mm, mailfolder mf
WHERE mf.mailfolderid = mm.mailfolderid
AND mf.userid = 1 AND mm.userid = 1
GROUP BY mf.mailfolderid
If you want I can give a schema for both tables but you shouldn't need it, I think.