BETWEEN operator in BigQuery

The BETWEEN operator in BigQuery is used to filter the result set within a certain range. It selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive, meaning it includes both the start and end values.

SQL Syntax

SELECT column_name(s)
FROM `project_name.dataset.table_name`
WHERE column_name [NOT] BETWEEN value1 AND value2;    

Example: Select the records where the study_id is between 200 and 300. Both values are inclusive.

SQL

SELECT *
FROM `bigquery-public-data.ebi_mgnify.study`
WHERE study_id BETWEEN 200 AND 300;    

The output of the above query is shown below:

BETWEEN operator in BigQuery

Let’s select the records where the study_id is not between 200 and 300. Both values are inclusive.

SQL

SELECT *
FROM `bigquery-public-data.ebi_mgnify.study`
WHERE study_id NOT BETWEEN 200 AND 300;    

The output of the above query is shown below:

BETWEEN operator in BigQuery