EXISTS Operator in SQL
Level 496 keystrokes
EXISTS returns TRUE if the subquery returns at least one row; here it finds customers with any order.
SQL code
-- Return the names of matching customers1SELECT2 name3FROM -- c is an alias the subquery uses to refer to the current customer4 customers c5WHERE -- TRUE as soon as the subquery finds one row; the search can stop there6 EXISTS ( -- Only existence matters, so the selected value is just 17 SELECT 18 FROM orders o -- Correlated: look for orders of the current customer c.id9 WHERE o.customer_id = c.id10 );Output
+-------+ | name | +-------+ | Alice | | Bob | +-------+ 2 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
.× 2_× 1;× 1(× 1)× 1=× 1