The SQL Between operator is used to filter the results of a query by specifying a range of values. This operator is inclusive, meaning it will include the start and end values in the result set.
SQL Between Syntax
SQL
x
1
SELECT column_name(s)
2
FROM table_name
3
WHERE column_name BETWEEN value1 AND value2;
SQL Between Finding Patients Born Between Dates Example
This query searches the Patients table for records where the dob (date of birth) falls between the specified range.
SQL
1
1
SELECT first_name, last_name, dob
2
FROM Patients
3
WHERE dob BETWEEN '1980-01-01' AND '1990-12-31';
SQL Between Selecting Appointments Within a Specific Date Range Example
This query filters the Appointments table to show appintments scheduled within the given date range, including the specified start and end dates.
SQL
1
1
SELECT appointment_id, patient_id, doctor_id, appointment_date
2
FROM Appointments
3
WHERE appointment_date BETWEEN '2024-07-20' AND '2024-07-25';