SQL EXISTS Keyword
The EXISTS keyword is used to check whether a subquery returns any rows. It returns TRUE if the subquery produces one or more results.
SQL EXISTS Syntax
SELECT column1
FROM table1
WHERE EXISTS (
SELECT column2
FROM table2
WHERE condition
);SQL EXISTS Example
This example lists all doctors who have at least one appointment in the Appointments table.
SELECT first_name, last_name
FROM Doctors
WHERE EXISTS (
SELECT appointment_id
FROM Appointments
WHERE Appointments.doctor_id = Doctors.doctor_id
);


