View Single Post
Old Mar 23rd, 2008, 8:52 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: MySQL - Basic Combining Of Queries

I was saying I need the username of every user_id I fetch, on top of the row I originally obtained. I can already do that with the MySQL queries I posted above. I'm now looking for a way to combine the queries so that I don't have to make 1+2*N queries. Instead just 1 query.

Modifying what you posted at the bottom might work. I will try some of that out. Thanks.

Edit: I can do it with one user id. Here's an example of where I need to output a table of ranks, and at the same time get the user name for every user_id.

MySQL Syntax (Toggle Plain Text)
  1. SELECT $table_ranking.*, $table_user.name
  2. FROM $table_ranking INNER JOIN $table_user
  3. ON $table_ranking.user_id=$table_user.user_id AND $table_ranking.game_id=$game_id

The problem comes from extending this to get the usernames of both user_id1 and user_id2 for each row. It seems like I would need multiple joins to accomplish that. Maybe I can try screwing around with nested joins.

Last edited by Sane; Mar 23rd, 2008 at 9:14 PM.
Sane is offline   Reply With Quote