Query
In one line
A query is a statement written in SQL (or another query language) that asks the database to perform an operation.
In simple words
A query is a command you send to the database to do something — most commonly to retrieve data, but also to insert, update, or delete it. In SQL, a query is a text statement like SELECT * FROM users WHERE age > 18.
When you run a query, the database parses it, builds an execution plan (deciding which indexes to use, how to join tables), executes the plan, and returns the result set.
Queries can be simple (read from one table) or complex (join many tables, aggregate data, use subqueries). Writing efficient queries is a key database skill — a poorly written query on a large table can take seconds or minutes instead of milliseconds.
Example
-- A query that finds active users over 18
SELECT name, email
FROM users
WHERE age > 18 AND active = TRUE
ORDER BY name;This query reads from the users table, filters by age and active status, and sorts by name.
Related terms
Related Resources
Related Lessons
- Select Queries
Learn how to write SELECT queries.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.