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