I’ve been tying for hours now to get a particular result and haven’t found any answer on the web – and as I’m not an SQL expert at all, I’m asking a question here.
I have 3 tables: user (id, name…), cars (id, type, color, engine power…) and an intermediary table to save all the scores users gave to the car: scores (id, user_id, car_id, score).
I’m trying to find a query that could return for one particular user, all the cars that he hasn’t rated yet. I’ve tried the following but it returns null:
$q=mysql_query("SELECT * FROM cars LEFT OUTER JOIN scores ON cars.id = scores.car_id WHERE scores.user_id != ('".$userId."')");
Does someone have a clue?
where
?is the ID of that particular user.A composite index in
scoresover(car_id, user_id)is useful here.