Code:
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
Assuming MySQL, you could put all three conditions into the FROM clause. I have learned that this is not typically what you want in the case of a two table join. Putting multiple conditions into the JOIN ... ON clause is used when you want to... lets call it "persuade" MySQL to join a certain way. It seems much more appropriate to put the extra two conditionals into the WHERE clause. However, for the sake of showing you how it would be done in the ON clause:
Code:
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);
Additionally, I would not write values from PHP variables directly into the query. Possibly a format string is better? You could use sprintf(%d) to force $current_user->ID to be an integer.
tl;dr Parenthesis are your friend.
Bookmarks