First page Back Continue Last page Image

A Query using The EXISTS Keyword

SELECT vendor_id, vendor_name, vendor_state

FROM vendors

WHERE NOT EXISTS

(SELECT *

FROM invoices

WHERE vendor_id = vendors.vendor_id)

Let’s say we want to know all the Vendors we have in our database who have no invoices, to do this we could use the EXISTS Keyword (Actually NOT EXISTS)

The subquery here is making a list of all the vendors who have invoices

The WHERE NOT EXISTS will then only list vendors not in the list created by the subquery