View Single Post
Old Mar 24th, 2008, 7:46 AM   #4
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 214
Rep Power: 3 Seif is on a distinguished road
Re: MySQL - Basic Combining Of Queries

Theres no reason why you need multiple queries. if you want every name for user_id1 and user_id2, just add that condition clause to the join. If you are concerned of duplicate name entries in the view from the query, then add a distinct to the statement.

I'm still having a bit of a job visualizing what your problem actually is. are user_id1 and user_id2 unique values? do they both make up a composite key ? it's even more confusing in your second post with differing table and field names.
If you cannot create a view from one query between two tables, then maybe you should reconsider the design of your database for performance gain.

The following single query "should" select a distinct set of names in table user for each user_id and game_id entry in table_ranking.

MySQL Syntax (Toggle Plain Text)
  1. SELECT DISTINCT $table_ranking.*, $table_user.name
  2. FROM $table_ranking INNER JOIN $table_user
  3. ON $table_ranking.user_id=$table_user.user_id OR $table_ranking.user_id=$table_ranking.game_id
Seif is offline   Reply With Quote