SQL SQL MOC


The EXISTS command checks for the existence of records in a subquery.

Unlike typical subqueries, the subquery is evaluated for each record in the parent query, which makes it inefficient.

SELECT firstName, lastName
FROM customers
WHERE EXISTS
    (SELECT customerId
    FROM orders
    WHERE customerId = customers.customerId);