SELECT categoryID, categoryName, (
SELECT COUNT(*)
FROM products
WHERE products.categoryID = categories.categoryID
) AS productCount
FROM categories;
EXISTS operator
WHERE [NOT] EXISTS (subquery)
SELECT c.customerID, firstName, lastName
FROM customers c
WHERE NOT EXISTS (
SELECT * FROM orders o WHERE c.customerID = o.customerID
);
EXISTS operator to test that one or more rows are returned by the subquery. You can also use the NOT operator with the EXISTS operator to test that no rows are returned by the subquery.