homepage Welcome to WebmasterWorld Guest from 54.163.70.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
left join with extra conditions
trouble with left join and extra conditions
frankstuner




msg:4528445
 4:29 pm on Dec 15, 2012 (gmt 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.

 

LifeinAsia




msg:4528879
 5:53 am on Dec 17, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved