BETWEEN

SQL BETWEEN Keyword

The BETWEEN keyword in SQL is used in a WHERE clause to filter the result set within a range. This range can consist of numbers, text, or dates, and is inclusive—meaning the start and end values are included in the result.

Tutorials dojo strip

SQL BETWEEN Syntax

SQL

To exclude values within the range, use:

SQL

SQL BETWEEN Example with Patients Table (Numeric Range)

This query returns all patients with patient_id values from 2 to 5, including both endpoints.

SQL

SQL NOT BETWEEN Example with Prescriptions Table (Text Range)

The following SQL statement selects all prescriptions where the medication_name is not alphabetically between 'Amoxicillin' and 'Ibuprofen, This query returns all medications outside the alphabetic range from 'Amoxicillin' to 'Ibuprofen'.

SQL

SQL BETWEEN Example with Appointments Table (Date Range)

This query will return all appointment records with a date and time from July 20, 2024 to July 25, 2024, including those dates.

SQL

SQL BETWEEN Labs

Tutorials dojo strip