BeginnerCoder

Lesson 16 — EXISTS

EXISTS: is there at least one?

EXISTS (subquery) is true when the subquery returns at least one row. It is usually correlated: for each customer, check whether an order exists for them. The database can stop at the first match, so it is fast. NOT EXISTS finds rows with no match.

SELECT title FROM courses c
WHERE EXISTS (SELECT 1 FROM signups s WHERE s.course_id = c.id)

Why it matters: "customers who ordered", "users who never logged in" — yes/no questions about related rows.

Want it another way?
Task

Fill in the WHERE inside EXISTS so it matches orders of the current customer. Expected: Ann and Cy.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with SQL Deep Dive

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.