An understandable SQL query example

Read a small SELECT query and adapt it to a test database without executing code here.

Updated 29 Sep 2026

A SELECT statement asks a database for rows. The column list controls which values are returned, FROM identifies the source table, and WHERE restricts the result. ORDER BY makes the ordering explicit. Without an ordering clause, you should not depend on the database returning rows in a particular sequence. The example uses an invented tasks table. It selects open tasks and orders them by due date and identifier. The second ordering column makes rows with the same due date deterministic. Adapt the table and column names to your own schema before trying the query in an appropriate test environment. Parameter syntax depends on the database driver or framework. The named placeholder in this example is intended to be bound by an application, not assembled through string concatenation. Use the prepared-query facilities supplied by your driver for values received from users. Do not replace that step by manually escaping a value copied from an online example. Pastzo displays SQL as text; it does not connect to a database or execute the query. A syntactically plausible query can still be unsuitable for a real schema or expensive on a large table. Check the relevant database documentation, available indexes and expected result before using it in an application. When sharing a query for help, replace customer names and private identifiers with invented values. Include a minimal table description and the expected result rather than exporting a production table. Keep credentials and connection strings out of the shared example.
SELECT task_id, title, due_date
FROM tasks
WHERE status = :status
ORDER BY due_date ASC, task_id ASC;

-- Bind :status to the value required by your application.
-- This example is displayed only; nothing is executed.