Skip to content
IT glossary
DatabasesUpdated December 3, 2026

SQL

You use SQL to read and change data in database tables. It also lets you define tables and set rules for what they can store.

What SQL does

SQL stands for Structured Query Language. Think of it as the language you use to ask a database a question: “Which products are running low?” or “How many orders did each customer place?” You can also use it to insert rows, update records, and define rules such as requiring each product to have a unique identifier.

SQL is not a database engine. PostgreSQL, MySQL, and SQLite are engines that understand SQL. They share a standard, but their dialects differ in areas such as date functions and how they handle conflicting inserts. Check which engine a query is meant to run on before copying it into an application.

From a query to a result

SQL is mostly declarative. You describe the rows you want, and the engine decides how to get them. For example, given a filter on a customer ID, the engine might use an index to find matching orders or scan the table. Two queries can return the same rows yet run differently. If performance matters, inspect the execution plan with EXPLAIN rather than guessing from the query text.

Example: find repeat buyers

Suppose orders contains one row per order and customer_id identifies the buyer. To find customers with at least two paid orders, first filter the orders, then count what's left for each customer:

SELECT customer_id, COUNT(*) AS paid_orders
FROM orders
WHERE status = 'paid'
GROUP BY customer_id
HAVING COUNT(*) >= 2
ORDER BY paid_orders DESC, customer_id;

WHERE filters individual orders. GROUP BY puts the remaining orders into one group per customer, and HAVING filters those groups by their counts. The result has one row per qualifying customer. ORDER BY lists the highest counts first and uses the customer ID to break ties. Without ORDER BY, the database does not guarantee any particular row order.

Where you'll use it and what to watch for

Application developers use SQL to fetch and update records and to apply schema changes. Analysts use it to build reports, and data engineers use it to transform data before it reaches those reports. Even with an ORM generating the queries, reading SQL helps you check what the application actually asks the database to do.

A join can increase the number of rows. If you join orders to order items, a single order can appear once per item, so COUNT(*) after the join may count items rather than orders. Also, NULL is not an empty string or zero: use IS NULL to check for it, not = NULL. For writes, remember that an UPDATE or DELETE without a WHERE clause applies to every row in the target table.

What interviewers look for

Many SQL exercises are about getting the right rows, not just writing valid syntax. Start by saying what one output row represents. Then test your query against a tiny example with missing matches or multiple matches. If the task asks for the latest order per customer, explain how you'll break ties when two orders have the same timestamp.