bhylu.com

Advertisements

SQL Between

BETWEEN checks a range and includes both endpoints. It reads naturally for a price interval, but inclusive boundaries need extra care when the column contains timestamps rather than plain dates.

Understand the idea

Here the range is 450 through 900 cents, inclusive. Both values are integers in the same unit. For a month of timestamps, prefer a half-open interval such as >= the first day and < the first day of the next month. That avoids guessing the last representable time of the final day.

Where to try it

Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.

SQLite sample data · MySQL / MariaDB sample data · See the sample tables

A worked example

SQLite

SELECT name, price_cents
FROM products
WHERE price_cents BETWEEN 450 AND 900
ORDER BY price_cents, product_id;

Read the result

Pencil set at 450 and Canvas bag at 900 are both included. Pocket notebook is below the lower boundary, and Desk lamp is above the upper boundary.

Try one change

Write the equivalent >= and <= conditions, then build a half-open January date filter on orders.