SQL In

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

SELECT column_name(s)
FROM table_name
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.

SELECT first_name, last_name, gender
FROM Patients
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.

SELECT first_name, last_name
FROM Doctors
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.

SELECT first_name, last_name, specialty
FROM Doctors
WHERE specialty IN ('Cardiology', 'Pediatrics', 'Neurology');




SQL In Visual Diagram




SQL In Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top