> -----Original Message-----
> From: Jeremy Morano [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 30, 2001 12:05 PM
> To: [EMAIL PROTECTED]
> Subject: JOIN 
> 
> 
> Sorry everone but I 'm having a hard time with joins

Let me give you a brief explanation of how Left Join works (or at 
least how I think it works  =P)

Lets say your two tables in the below query (users and picks) have
4 and 2 rows respectively.  If you were to do select * from users left
join picks on users.uid=picks.user_id you would get something like

| uid | username | user_id |
|   1 | Sheridan |       1 |
|   2 | Mark     |       2 |
|   3 | Jason     |    NULL |
|   4 | Henry    |    NULL |

That is, you had it show all the rows from both tables while checking
only the rows where users.uid has a value (and returning null if 
picks.user_id doesn't have an equal value).  Now what if you were to 
do select * from picks left join users on users.uid=picks.user_id?  
You would get

| user_id | uid  | username |
|       1    |    1 | Sheridan  |
|       2    |    2 | Mark       |  

because you told it to show you all the rows from both tables while
checking only the rows where picks.user_id has a value. It would
have returned null for both users.uid and users.username for any row
where user_id had a value that uid didn't.  For example, if picks had
the values (1,2,11) instead of (1,2) you would get

| user_id | uid  | username |
|       1    |    1 | Sheridan  |
|       2    |    2 | Susuan     |
|      11   | NULL | NULL|

Does that make sense?
 
> How do I add this clause:
> 
> users.uid <> selection.user_uid     from table selection 
> 
> to this query:
> 
> $sql = "SELECT users.uid, users.username
> FROM users LEFT JOIN picks
> ON users.uid = picks.user_id 
> WHERE picks.user_id IS NULL

I am not sure I am following you.  What are you trying to do exactly?
Are you trying to list all the entries in table users that do not have 
equivalents in either table picks or table selection?  If so I guess you 
could do something like:

select users.uid,users.username from users left join picks on users.uid =
 picks.user_id left join selection on users.uid = selection.user_uid where 
picks.user_id is null and selection.user_uid is null;

If this is not what you are trying to accomplish, reply with a clear 
description of what you are trying to accomplish.
 
> Thank You.

No Problem.  Hope that helps.

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to