joining two queries into one

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
theclay7
Forum Commoner
Posts: 50
Joined: Wed Feb 19, 2003 3:17 am

joining two queries into one

Post by theclay7 »

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?
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

u can get user UserID in the first query by adding it to the fields selected.
this is because you giving it certain critera to follow. if that makes sense
kdeveron
Forum Newbie
Posts: 2
Joined: Sat Apr 12, 2003 5:11 pm

Post by kdeveron »

Also check out mysql manager (you can search on that name on google). It does a great job of giving you a graphical way of building queries that use multiple joins.
Post Reply