Junior — Middle
Have you used the EXISTS operator in SQL queries?
sobes.tech AI
Answer from AI
The EXISTS operator in SQL is used to check for the existence of rows that satisfy a subquery. It returns TRUE if the subquery returns at least one row, and FALSE if it does not.
Example usage:
SELECT * FROM employees e
WHERE EXISTS (
SELECT 1 FROM departments d
WHERE d.id = e.department_id AND d.name = 'Sales'
);
This example selects all employees who work in the "Sales" department. EXISTS is efficient for checking the presence of related data without needing to return the data itself.