sqlcmd.net validated sql reference
beginner filtering MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Rows Within A Range With BETWEEN

Use `BETWEEN` to match rows where a column falls within an inclusive lower and upper bound.

Docker-validated Not currently validation-green

Return orders with amounts between 100 and 300

Order 1 (50) is below the range and order 4 (350) is above it. BETWEEN includes the endpoints — if the data had a row with amount = 100 or amount = 300, it would also be returned.

Rows loaded before the example query runs.
Setup
CREATE TABLE orders (id INT, amount INT);

INSERT INTO
  orders (id, amount)
VALUES
  (1, 50),
  (2, 150),
  (3, 250),
  (4, 350);
Shared across supported engines.
SQL
SELECT
  id,
  amount
FROM
  orders
WHERE
  amount BETWEEN 100 AND 300
ORDER BY
  id;
Returned rows for the shared example.
idamount
2150
3250

Output is identical across all engines.

Where this command helps.

  • returning rows within a numeric or date range
  • finding records that fall inside a lower and upper bound

What the command is doing.

BETWEEN low AND high is inclusive on both ends — equivalent to column >= low AND column <= high. It works with numbers, dates, and strings. NOT BETWEEN excludes the range instead. For date ranges, ensure consistent handling of time-of-day components to avoid off-by-one edge cases.