Friday, April 24, 2009

EXISTS

Find accounts without contact


SELECT *
FROM ACCOUNT A
WHERE NOT EXISTS (SELECT 1
FROM CONTACT C
WHERE C.ACCOUNT_ID = A.ACCOUNT_ID)
You can also query like that:
SELECT *
FROM ACCOUNT A
WHERE A.ACCOUNT_ID NOT IN
(SELECT DISTINCT ACCOUNT_ID
FROM CONTACT)


No comments:

Post a Comment