Ten Terms You Meet in Your First SELECT Queries

SELECT queries are built from a small set of keywords and ideas. Here are ten you will meet in your first weeks, each with a plain explanation and a tiny example using a made-up films table with columns title, year and genre.

1. SELECT

Says which columns you want back.

SELECT title, year FROM films;

SELECT * means "every column", handy for exploring but best avoided in app code.

2. FROM

Says which table the rows come from. Every basic SELECT has one.

SELECT title FROM films;

3. WHERE

Keeps only rows that match a condition.

SELECT title FROM films WHERE genre = 'comedy';

Text values go in single quotes; numbers do not.

4. ORDER BY

Sorts the results. Add DESC for largest or latest first.

SELECT title, year FROM films ORDER BY year DESC;

Without ORDER BY, the database may return rows in any order.

5. LIMIT

Returns only the first few rows.

SELECT title FROM films ORDER BY year DESC LIMIT 5;

SQL Server uses TOP instead, as in SELECT TOP 5 ....

6. DISTINCT

Removes duplicate results.

SELECT DISTINCT genre FROM films;

Each genre appears once.

7. Alias (AS)

Gives a column or table a temporary nickname in the result.

SELECT title AS film_name FROM films;

Aliases make results easier to read and are very common in JOINs.

8. Aggregate function

A function that turns many rows into one value, such as COUNT, SUM, AVG, MIN or MAX.

SELECT COUNT(*) FROM films WHERE year >= 2000;

9. GROUP BY

Splits rows into groups so an aggregate runs once per group.

SELECT genre, COUNT(*) FROM films GROUP BY genre;

Every column in the SELECT that is not inside an aggregate should be in GROUP BY.

10. NULL

A special marker meaning "unknown" or "missing". It is not zero and not empty text. Test it with IS NULL or IS NOT NULL.

SELECT title FROM films WHERE year IS NULL;

The ten at a glance

TermOne-line meaning
SELECTWhich columns
FROMWhich table
WHEREWhich rows
ORDER BYWhat order
LIMITHow many
DISTINCTNo repeats
ASA nickname
AggregateMany rows into one value
GROUP BYOne result per group
NULLUnknown or missing

The order they appear in

When several appear together, SQL expects them in this order: SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT. A simple way to remember it: decide what, from where, which ones, how grouped, how sorted, how many.

Practise them

Test yourself with the SELECT quiz, and keep your practice queries in the query notebook template.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.