First of all, for organization purposes we will keep the table of interest (product) on the left, and the reference (highlights) on the right, so we can use a LEFT JOIN
.
The LEFT JOIN
is appropriate, because we want what’s on the left, even if it doesn’t match, and we don’t care what’s on the right with no match.
Then let’s condition to return where the data on the right is null.
The result is this:
SELECT
p.*
FROM
produto p
LEFT JOIN destaques d ON p.idProduto = d.idProduto
WHERE
ISNULL(d.idProduto);
Note that we cannot break the link to JOIN
, which is this:
ON p.idProduto=d.idProduto
after all, this is the condition that relates the two tables. Once related, what filters the results is the WHERE
. And the desired condition is when there is no match, therefore null:
WHERE ISNULL(d.idProduto);
Understand the JOIN
s suitable for every situation is important. I suggest reading this:
What is the difference between INNER JOIN and OUTER JOIN?