i use a sql query like this to get some results i need:
SELECT
*
FROM
pictures p
WHERE
p.id NOT IN
(
SELECT
picture_id
FROM
guesses g
WHERE
g.user_id = XXX
)
AND
p.user_id != XXX
;
Relation is as follows: A user has many pictures and a picture belongs to one user. A user has many guesses and a guess belongs to one picture. The tricky part is that a user is only allowed one guess for the same picture.
XXX = $user_id
I guess that there is a way to rewrite this sub-select using a left join but i can’t get it working.
Can anyone help?
Anja
Because it is a
NOT INcondition you should use aLEFT OUTER JOIN. This is the direct translation to left outer join of your query: