Combine these 4 selects into 1 statment?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
recci
Forum Commoner
Posts: 42
Joined: Tue Jul 29, 2008 10:01 pm

Combine these 4 selects into 1 statment?

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Combine these 4 selects into 1 statment?

Post by VladSun »

UNION could be helpful
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Combine these 4 selects into 1 statment?

Post by Christopher »

I see 5 statements. ;)

How do mb_category, mb_list and mb_messages relate to each other?
(#10850)
Post Reply