PDA

View Full Version : joining two queries into one


kenny873
04-08-2003, 04:11 AM
i have a forum and want to get the data of "Who is the last person updating the message with messageID = $q_id."

I am very new to sql, so I choose to use two mysql query to get the result, however, since I am implementing this in a php called function, how can I join the following two queries into one...

1) select max(q_id) from game_forum where parent_q_id = $q_id OR q_id = $q_id ;

--> parent_q_id = $q_id means that it is a child thread.
--> it then pass the result($LastUpdQID) to the following query.

2) select userID from game_forum where q_id = $LastUpdQID;

how can I joing these two queries into one and get the last updated userID?

raf
04-08-2003, 01:07 PM
You can use a subquery (known for MySQL as a subselect) but this only works from version 4.1 on.
more info (in fact, all the info you need:) )
http://www.mysql.com/doc/en/ANSI_diff_Sub-selects.html

Or you can probably use a join or something, but we need to know how your db is designed to help you on that