Page 1 of 1

Combine these 4 selects into 1 statment?

Posted: Tue Nov 25, 2008 4:51 pm
by recci
Iv been trying to combine these 4 sql querys into one but its just too complex for me My brains about to explode!

SELECT * ID, category_name FROM mb_category";

SELECT * FROM mb_list";


SELECT COUNT(ID) AS Posts FROM mb_messages WHERE (mb_id = 2)";


SELECT COUNT(ID) AS Threads FROM mb_messages WHERE (mb_id = 2) AND (parent = 0)";

SELECT poster_id, title FROM mb_messages WHERE (ID = (SELECT MAX(ID) AS message FROM mb_messages mb_messages_1 WHERE (mb_id = 2)))";



Anybody able to have a go at it?

Re: Combine these 4 selects into 1 statment?

Posted: Tue Nov 25, 2008 5:32 pm
by VladSun
UNION could be helpful

Re: Combine these 4 selects into 1 statment?

Posted: Tue Nov 25, 2008 5:36 pm
by Christopher
I see 5 statements. ;)

How do mb_category, mb_list and mb_messages relate to each other?