My query is:
SELECT Pics.ID, Pics.ProfileID, Pics.Position, Rate.ID as RateID, Rate.Rating, Rate.ProfileID, Gender
FROM Pics
INNER JOIN Profiles ON Pics.ProfileID = Profiles.ID
LEFT JOIN Rate ON Pics.ID = Rate.PicID
WHERE Gender = 'female'
ORDER BY Pics.ID
And results are:
ID ProfileID Position RateID Rating ProfileID Gender
23 24 1 59 9 42 female
24 24 2 33 8 32 female
23 24 1 53 3 40 female
26 24 4 31 8 32 female
30 25 4 30 8 32 female
24 24 2 58 4 42 female
Now I want to do another query which would be: If Rate.ProfileID = 32, remove any rows that contain that same Pics.ID
so left with:
ID ProfileID Position RateID Rating ProfileID Gender
23 24 1 59 9 42 female
23 24 1 53 3 40 female
and also remove any duplicate Pics.ID so just one of the above as they are both = 23 so left with :
23 24 1 59 9 42 female or 23 24 1 53 3 40 female
LEFT JOIN Rate ON Pics.ID = Rate.PicID and Rate.ProfileID = 32if you doLEFT JOIN Rate ON Pics.ID = Rate.PicID where gender='female' and Rate.ProfileID =32then you basically make the left join an inner as you eliminate the nulls generated from the left join in the where clause. Null <> 32!24 24 2 58 4 42 female(last row) not in the expected results of the modified query?