Interview Question

What is EXISTS clause?

EXISTS checks whether a subquery produces any row.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

EXISTS is true when its subquery returns at least one row. • The selected expressions inside the subquery do not determine the Boolean result. • It is commonly used for correlated existence tests. • NOT EXISTS tests that no matching row exists.

💡 SQL Example

SELECT name FROM departments d WHERE EXISTS (SELECT 1 FROM employees e WHERE e.department_id = d.department_id);

Result

Departments with employees

⚡ Quick Revision

EXISTS checks whether a subquery produces any row.