The SQL In operator is used to filter records based on a list of values. It’s a convinient way to check if a column value matches any value within a specified list, allowing you to avoid using multiple OR conditions.
SQL In Syntax
SQL
x
1
SELECT column_name(s)
2
FROM table_name
3
WHERE column_name IN (value1, value2, ...);
SQL In Filter Patients by Gender Example
This query fetches all patients since they all match either ‘M’ or ‘F’ which are the Male and Female gender.
SQL
1
1
SELECT first_name, last_name, gender
2
FROM Patients
3
WHERE gender IN ('M', 'F');

SQL In Using Subquery with In Example
This query will return all doctors who have at least one scheduled appointment.
SQL
1
1
SELECT first_name, last_name
2
FROM Doctors
3
WHERE doctor_id IN (SELECT doctor_id FROM Appointments);

SQL In Find Doctors with Specific Specialties Example
This query will return doctors who practice specific specialties.
SQL
1
1
SELECT first_name, last_name, specialty
2
FROM Doctors
3
WHERE specialty IN ('Cardiology', 'Pediatrics', 'Neurology');

SQL In Visual Diagram
