BETWEEN Operator

SQL · Filtering Rows

Theory

BETWEEN checks whether a value falls inside a range, including both ends. salary BETWEEN 50000 AND 75000 is exactly the same as salary >= 50000 AND salary <= 75000, so ₹50,000 and ₹75,000 both match. NOT BETWEEN keeps values outside the range.

The low value must come first: BETWEEN 75000 AND 50000 matches nothing. It works with numbers, dates and text (text uses alphabetical order). With timestamps be careful: order_date BETWEEN '2024-01-01' AND '2024-01-31' misses times later on 31 January, because '2024-01-31' means midnight. For time ranges the safer pattern is order_date >= '2024-01-01' AND order_date < '2024-02-01'. A NULL value never matches.

Why we use it

Range filters (salary bands, date windows, score ranges) are very common. BETWEEN states them in a short, readable way and avoids writing two comparisons joined by AND.

When to use it

Use BETWEEN for inclusive ranges on numbers or plain dates. For timestamps or when you need an exclusive upper bound, use >= and < instead. For a fixed list of values, use IN.

How it works

  1. Read a row
  2. Compare the value with the low bound
  3. Is value >= low? Yes: Compare with the high bound. No: Discard the row.
  4. Is value <= high? Yes: Keep the row (ends included). No: Discard the row.
  5. Move to the next row

Syntax

SELECT columns FROM table
WHERE column BETWEEN val1 AND val2;

Example

SELECT * FROM employees WHERE salary BETWEEN 40000 AND 80000;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic