Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: open

Message Too Old, No Replies

left join with extra conditions

trouble with left join and extra conditions

     
4:29 pm on Dec 15, 2012 (gmt 0)

New User

joined:Oct 12, 2011
posts: 25
votes: 0


I'm trying to setup a rating app for images. I want to display the images that haven't been rated by the current logged user.

This covers two tables, I've successfully joined the tables but the extra conditions:
1. must be an image
2. exclude any images that have already been rated by the current user
are not working.

Its displaying the results as if the 2 AND conditions aren't there at all.

SELECT ver_data_media.id, ver_data_media.value, ver_data_media.ref, ver_data_media.type, ver_data_rating.a
FROM ver_data_media
LEFT JOIN ver_data_rating
ON ver_data_media.ref = ver_data_rating.a
AND ver_data_media.type = 'image'
AND ver_data_rating.a != $current_user->ID


Any advice would be greatly appreciated, thanks Frank.
5:53 am on Dec 17, 2012 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5550
votes: 24


Try:
SELECT ver_data_media.id, ver_data_media.value, ver_data_media.ref, ver_data_media.type, ver_data_rating.a
FROM ver_data_media
LEFT JOIN ver_data_rating
ON ver_data_media.ref = ver_data_rating.a
WHERE ver_data_media.type = 'image' AND ver_data_rating.a != $current_user->ID