bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL EXISTS Operator

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind SQL EXISTS Operator?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___(s)
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The EXISTS operator evaluates to TRUE if the subquery returns at least one row, and FALSE otherwise.
The EXISTS operator is used in a WHERE clause to check whether a subquery returns any rows.
The SQL EXISTS Operator

The SQL EXISTS Operator

The EXISTS operator is used in a WHERE clause to check whether a subquery returns any rows.

The EXISTS operator evaluates to TRUE if the subquery returns at least one row, and FALSE otherwise.

EXISTS Syntax

SELECT
column_name(s)
 FROM
table_name
WHERE EXISTS (
subquery
);

Demo Database

Below is a selection from the "Products" table in the Northwind sample database:

ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18.00
2Chang1124 - 12 oz bottles19.00
3Aniseed Syrup1212 - 550 ml bottles10.00
4Chef Anton's Cajun Seasoning2248 - 6 oz jars22.00
5Chef Anton's Gumbo Mix2236 boxes21.35

And a selection from the "Suppliers" table:

SupplierIDSupplierNameContactNameAddressCityPostalCodeCountry
1Exotic LiquidCharlotte Cooper49 Gilbert St.LondonEC1 4SDUK
2New Orleans Cajun DelightsShelley BurkeP.O. Box 78934New Orleans70117USA
3Grandma Kelly's HomesteadRegina Murphy707 Oxford Rd.Ann Arbor48104USA
4Tokyo TradersYoshi Nagase9-8 Sekimai Musashino-shiTokyo100Japan

Previous

SQL HAVING Clause

Next

SQL ANY Operator