# Database Query

> A request sent to a database. It reads some data or changes it.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** Query, SQL Query

## Think of it like

Think of it like a question you hand to a librarian. They go to the shelves and come back with the answer.

## Definition

A query is a request you send to a database, either to read data or to change it. A read query asks for rows that match some conditions, like all orders over 50 euros. Others add, change or delete rows. The database plans how to answer each query, using indexes if it can. A slow query is one of the commonest reasons an app feels slow.

## Example

Jack's admin page runs one query to list today's orders. It returns 120 rows in 8 milliseconds.

## Example code

```sql
SELECT name, COUNT(orders.id)
FROM customers
LEFT JOIN orders ON orders.customer_id = customers.id
GROUP BY customers.id;
-- Emma | 2
-- Jack | 1
-- Lucy | 0
```

How many orders each customer has, even the ones with none.

## Why it matters

Every screen that shows data runs queries behind it. Their speed is the app's speed.

## Common mistake

Asking for every column with SELECT * when you need two. It moves far more data than needed.

## Three principles

- **Read or change.** Questions and edits are both queries.
- **Planned for speed.** The database picks the route.
- **Ask for less.** Only the rows and columns you need.

## Related terms

- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)
- [Database Index](https://learn.benibix.com/term/development/database-index)
- [SQL Join](https://learn.benibix.com/term/development/join)
- [Database](https://learn.benibix.com/term/development/database)
- [SELECT Statement](https://learn.benibix.com/term/development/select-statement)
- [WHERE Clause](https://learn.benibix.com/term/development/where-clause)

---

Source: https://learn.benibix.com/term/development/query
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
