Stockertim Dictionary · Technology
SQL query
Also called SQL statement, SELECT statement, database query
In short
A written request to a relational database, in SQL, that describes which rows and columns to return and how to filter, combine, summarise and sort them.
- Beginner
- Concept
- Checked
In detail
An SQL query states the result that is wanted and leaves the database to work out how to produce it. The simplest form names the columns and the table: SELECT name, city FROM members. Further clauses narrow and shape the answer. WHERE keeps rows that meet a condition, ORDER BY sorts them, and LIMIT caps how many come back.
Each clause has a fixed place in the written text: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, then LIMIT. Keywords are conventionally written in capitals and the names of tables and columns in lower case, which makes a long query easier to scan. Text values go inside single quotes, numbers do not, and a semicolon ends the statement.
A query that only reads data, a SELECT, changes nothing in the database, which makes it a safe place to learn. Other statements do change data: INSERT adds rows, UPDATE edits them and DELETE removes them. An UPDATE or DELETE without a WHERE clause acts on every row of the table, which is why careful teams run the matching SELECT first and look at the rows it returns.
The result of a query is itself a table, so it can be exported, charted or used inside a larger query. Because the text records every step, a query can be saved, rerun next month on new data, reviewed by a colleague and compared line by line with an earlier version, which a series of manual filters in a spreadsheet cannot offer.
Worked example
A gym chain in Cape Town wants the ten most recent sign-ups at its Sea Point branch.
- Write:
SELECT member_id, name, joined_on FROM members WHERE branch = 'Sea Point' ORDER BY joined_on DESC LIMIT 10; - The database filters the members table to one branch, sorts by joining date with the newest first and returns ten rows.
A ten-row table that the manager can rerun every Monday without editing anything.
In practice
Analysts write queries to pull data for reports, check data quality and answer one-off questions from colleagues. AI assistants can draft a query from a plain-language request, but the person asking still reads it, runs it on a small sample and checks the row count before trusting the figures.
Watch out
- A query that runs without an error can still answer a different question from the one intended; check a few rows by hand.
- Never run UPDATE or DELETE on live data without first running the same WHERE condition as a SELECT.
Learn it properly
Official sources
- The AQuA Book: guidance on producing quality analysis for government · HM Treasury
- Reproducible Analytical Pipelines strategy · Government Analysis Function
Facts last checked on 9 November 2026.
Education, not advice: the Stockertim Dictionary explains what terms mean. It never recommends buying or selling anything.