Today I tried several more complex MySQL queries, and I noticed that MySQL LEFT JOIN does not work with the WHERE clause. I mean, it returns some records, but does not return those that are empty on the right side.
For example, let's say we have tables:
albums albums_rap
id artist title tracks; id artist title rank
---- -------- ---------- ---------------; ---- --------- ----- --------------
1 John Doe Mix CD 20; 3 Mark CD # 7 15
2 Mark CD # 7 35; And when I run this query:
SELECT t1.artist as artist, t1.title as title, t1.tracks as tracks, t2.rank as rank, FROM albums as t1 LEFT JOIN albums_rap as t2 ON t1.artist LIKE t2.artist AND t1.title LIKE t2.title WHERE t2.rank != 17
I get this:
artist title tracks rank
------ ----- ------ -----
Mark CD # 7 35 15
but when I replace "WHERE" with "AND" in this query, I get:
artist title tracks rank
------ --------- ------ -----
Mark CD # 7 35 15
John Doe Mix CD 20 NULL
Why the first does not return records with "NULL" (zero is not equal to 17 ...)
I hope you understand what I had in mind, and you will somehow explain the difference to me. Sorry for my poor English, this is not my native language.
source share