🗃️Database Query
Also known as Query, SQL Query
A request sent to a database. It reads some data or changes it.
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.
Example
Jack's admin page runs one query to list today's orders. It returns 120 rows in 8 milliseconds.
Why it matters
Every screen that shows data runs queries behind it. Their speed is the app's speed.
Definition
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 | 0Common mistake
Key takeaways
- 1Read or change. Questions and edits are both queries.
- 2Planned for speed. The database picks the route.
- 3Ask for less. Only the rows and columns you need.