Consider having these two tables and the following queries:
SELECT Product. * FROM Product WHERE EXISTS ( SELECT * FROM Codes WHERE Product.P_code <> Codes.P_code)
SELECT Product. * FROM Product WHERE NOT EXISTS ( SELECT * FROM Codes WHERE Product.P_code <> Codes.P_code)
Is the following reasoning correct?
1.The first query will produce two entries because there are two P_code rows in Codes that are not identical to the ones in Product. 2. The subquery will return two entries, but they will be eliminated by the NOT condition in the main query, which will return zero rows.
I am not sure how the reasoning in these queries works. I can easily predict when the query will print out 2 or 3 rows, but I do not know how it works in cases in which it may print 0 or 5 rows (depending on the EXISTS/NOT EXISTS condition and the equality/inequality sign).
Can somebody elaborate on this or send me a good reading? Thank you!