View Single Post
Old Mar 23rd, 2008, 8:28 PM   #2
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 213
Rep Power: 3 Seif is on a distinguished road
Re: MySQL - Basic Combining Of Queries

not sure I 100% follow what you mean but why not just use an OR statement ?

SELECT name FROM $table_user WHERE user_id=$user_id1 OR user_id=$user_id2

Ideally, if you are constructing a set of results from more than one table that reference each other using foreign keys, you can perform a series of joins to obtain what you need. There are multiple ways of performing a join:

SELECT table_user.name
FROM table_user,table_match
WHERE table_user.userid1 = table_match.userid1 OR
 table_user.userid2 = table_match.userid2

or

SELECT table_user.name
FROM table_user
INNER JOIN table_match
ON 
 table_user.userid1 = table_match.userid1 OR
 table_user.userid2 = table_match.userid2

Both commands should construct a list of names for each userid. Have a look at JOIN SQL statements. They should provide all that you need.
Seif is offline   Reply With Quote