MySQL SQLLesson 38Free preview
MySQL EXISTS
This lesson is part of MySQL · All levels
Summary
EXISTS is a subquery operator that returns TRUE if the subquery produces at least one row. EXISTS is often used to check the presence of related data in other tables, such as customers who have previously placed a order. Varian NOT EXISTS works the reverse, which is to return TRUE if the subquery does not produce a row at all.
Key points
- EXISTS is worth TRUE if the subquery produces at least one line
- NOT EXISTS is worth TRUE if the subquery does not generate a line
- Subquery conditions are often correlated, i.e. referring to columns from external queries
- MySQL can stop looking as soon as a match is found so it's more efficient for big data.
- The EXISTS result is only TRUE/FALSE/NULL, not a list of values
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.