About Lesson
MySQL EXISTS Operator
The EXISTS operator in MySQL is used to test for the existence of any rows returned by a subquery. If the subquery returns any rows, the EXISTS condition is TRUE; otherwise, it is FALSE.
Example:
SELECT employee_id, employee_name
FROM employees e
WHERE EXISTS (
SELECT 1
FROM orders o
WHERE o.employee_id = e.employee_id
);
This query retrieves the employee IDs and names from the employees table for employees who have placed orders.
The EXISTS operator is commonly used with correlated subqueries to check for the existence of related rows in another table.
Join the conversation