SQL BETWEEN with Dates
SQL BETWEEN with Dates is a SQL clause in the SELECT Queries category. BETWEEN is inclusive of both endpoints. With dates, careful about time portions of TIMESTAMP columns. The syntax is SELECT * FROM t WHERE date_col BETWEEN 'start' AND 'end';. It returns date range result. A typical example: -- DATE columns (safe): SELECT * FROM orders WHERE order_date BETWEEN '2026-01-01' AND '2026-06-06'; -- Includes: 2026-01-01 through 2026-06-06 -- TIMESTAMP columns (pitfall): SELECT * FROM orders WHERE created_at BETWEEN '2026-01-01' AND '2026-06-06'; -- Includes 2026-01-01 00:00:00 through 2026-06-06 00:00:00 -- MISSES: 2026-06-06 00:00:01 and later on June 6! -- SQL Server better approach: SELECT * FROM orders WHERE created_at >= '2026-01-01' AND created_at < DATEADD(DAY, 1, '2026-06-06'); -- Safer… A close relative is SELECT, which retrieves data from a table. The most fundamental SQL statement. A close relative is SELECT *, which selects all columns from a table.