Sottoquery con NOT EXISTS
La parola chiave NOT EXISTS funziona in modo analogo a EXISTS, con la differenza che la clausola WHERE in cui è specificata viene soddisfatta se la sottoquery non restituisce alcuna riga.
Per trovare, ad esempio, i nomi dei prodotti che non fanno parte della sottocategoria wheels:
USE AdventureWorks2008R2;
GO
SELECT Name
FROM Production.Product
WHERE NOT EXISTS
(SELECT *
FROM Production.ProductSubcategory
WHERE ProductSubcategoryID =
Production.Product.ProductSubcategoryID
AND Name = 'Wheels')
Vedere anche