Afficher un message
Vieux 22/08/2007, 17h23   #1
Critters
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Left join is not doing what I thought it should do.

I have 3 tables
A users table (userID, userName)
A leaderboard table (userID, score)
A friends table (userIDA, userIDB)

I would like to produce the following result:

userName, score, userIDA
Dave, 100, 1
Simon, 200, 5
Paul, 300, NULL

The 3rd record is NULL as there is no record in "friends" with a userIDB
matching users (or leaderboard) userID

I have tried this:

SELECT users.username, gameLeaderboards.playerpoints, friends.userA
FROM gameLeaderboards
JOIN users ON gameLeaderboards.userID = users.ID
LEFT JOIN friends ON gameLeaderboards.userID = friends.userB
WHERE friends.userA = 79760

The where is so there is only a value in the "userIDA" column if the
user is friends with userID 79760

But what I get instead of lots of records with 79760 and NULLs is just
records from the leaderboard table that have a matching userID in the
friend table, hmmf

Any ideas?

Thanks
-
Dave

  Réponse avec citation
 
Page generated in 0,05008 seconds with 9 queries