आप EXISTS
. का उपयोग कर सकते हैं :
SELECT category, categoryID
FROM categories AS c
WHERE EXISTS (SELECT 1
FROM products AS p
WHERE p.categoryID = c.categoryID )
या एक INNER JOIN
:
SELECT DISTINCT category, categoryID
FROM categories AS c
INNER JOIN products AS p ON p.categoryID = c.categoryID
या IN
ऑपरेटर:
SELECT category, categoryID
FROM categories
WHERE categoryID IN (SELECT categoryID FROM products)