Let’s say we run the following -
SELECT t.track_id, il.track_id, t.composer, t.composer NOT LIKE "%Angus%"
FROM track AS t
LEFT JOIN invoice_line AS il
ON t.track_id = il.track_id
ORDER BY t.track_id;
We will get an output like -
There’s at least one empty value for composer
there. Notice how in the last column, values are 0
or empty. If values were non-empty and the condition of NOT LIKE "%Angus%"
was met, we would see a 1
.
So, that’s our table right now. 0
s, 1
s or empty/NULL values.
Let’s run the following -
SELECT t.track_id, il.track_id, t.composer, t.composer NOT LIKE "%Angus%"
FROM track AS t
LEFT JOIN invoice_line AS il
ON t.track_id = il.track_id
WHERE t.composer NOT LIKE "%Angus%"
ORDER BY t.track_id;
Now we see only 1
s in the last column. WHERE
clause is filtering out 0
s and the empty/NULL values. If we want to include the NULL values, we need to specify that explicitly.
SELECT t.track_id, il.track_id, t.composer, t.composer NOT LIKE "%Angus%"
FROM track AS t
LEFT JOIN invoice_line AS il
ON t.track_id = il.track_id
WHERE t.composer NOT LIKE "%Angus%" OR t.composer is NULL
ORDER BY t.track_id;
But, if we move the condition to ON
SELECT t.track_id, t.composer, t.composer NOT LIKE "%Angus%"
FROM track AS t
LEFT JOIN invoice_line AS il
ON t.track_id = il.track_id
AND t.composer NOT LIKE "%Angus%";
we get
We see all the 0
s, 1
s and NULL values there.
But also focus on both track_id
s there. We are not filtering anything out here. We are joining on those two conditions separately.
It joins the tables on the track_id
s being the same, and it also joins the tables when the composer
is not Angus
. So, we end up getting a table satisfying both those joining conditions at the same time and not like a logical AND.
That’s what they mean by conjunction
the only difference is that the condition we’re checking isn’t an equality but, rather, a conjunction
We are not comparing those two like
-
1
AND 0
would output 0
-
1
AND 1
would output 1
, and so on
The tables are being joined to satisfy both the conditions, but the WHERE
clause is checking for equality as they state. Hopefully this clears it up.