views:

42

answers:

1

I would like to pull up a catalog of games, but I also want to know if a game is in a SPECIFIC member's (current member in session) list of games already. This information is stored in a table called gameslist, which is a joiner table that joines members and games gameslists(id,memberid,gameid,rank)

SELECT DISTINCT *, gameslists.memberid
FROM games 
INNER JOIN platforms ON games.platformid = platforms.id 
INNER JOIN titles ON games.titleid = titles.id 
INNER JOIN genres ON games.genreid = genres.id 
LEFT OUTER JOIN gameslists ON games.id = gameslists.gameid
WHERE platforms.id = 1
ORDER BY games.releasedate DESC
LIMIT 8

PROBLEM if a game is in the list of two members, it shows up twice, if it's in three lists, shows up three times, etc... the result is that I can tell if the game is in a current user's list, but the catalog display screws up by showing the same game twice (since it was found twice in gameslists)

http://i82.photobucket.com/albums/j277/melhusseini/Capture2.png

How can I fix this?

EDIT: The primary display criteria for the query should be determined by the catalog parameters (genre, release, date, etc...) not if the game is already in a member's list or not... the purpose of that part is to display an add/remove button based on that status

+2  A: 

In your outer join condition put the memberid of the specific member of interest.

LEFT OUTER JOIN gameslists ON
  games.id = gameslists.gameid and gameslists.memberid = 1

You can then test gameslists.memberid if it is null then the game was not in their list.

e.g.

case when gameslists.memberid is null then 0 else 1 end as InMembersList
Martin Smith
Thanks, that's awesome!
Mel