SQL '08: How to count all sku's in one table not found in another table
I would like to do something similar to this psuedo-SQL:
开发者_开发知识库SELECT COUNT(A.SKU)
FROM TableA as A
WHERE a.sku NOT IN TableB
Multiple solutions, example with EXISTS :
SELECT COUNT(A.SKU) AS your_count
FROM TableA
WHERE NOT EXISTS(SELECT NULL
FROM TableB
WHERE B.SKU = A.SKU);
You could also use EXCEPT :
SELECT COUNT(*)
FROM (
SELECT SKU
FROM TableA
EXCEPT
SELECT SKU
FROM TableB);
You could also use NOT IN, LEFT OUTER JOIN ... WHERE B.SKU IS NULL, etc.
精彩评论