SQL basics: the five clauses to learn first

SQL basics: the five clauses to learn first

By Omega Academy · 3 min read

SQL is the language used to ask questions of data stored in databases. It looks intimidating at first, but most everyday queries are built from just five clauses. Learn those and you can already answer a surprising number of business questions.

One clause, one job

A query reads almost like an English sentence. Each clause has a single, clear purpose, and you can read them top to bottom.

A SQL query broken into SELECT, FROM, WHERE, GROUP BY and ORDER BY, with a one-line explanation of each
The five clauses and what each one does.
Tip: write queries in the order you would explain them aloud. First decide what you want to see, then where it lives, then which rows matter, and finally how to group and sort it.

The clauses at a glance

Clause Question it answers Example
SELECT Which columns do I want? customer, amount
FROM Which table holds the data? orders
WHERE Which rows should be included? status = ‘Paid’
GROUP BY How should rows be combined? one row per customer
ORDER BY In what order should results appear? largest total first

The next step: joins

Real data is usually spread across several tables, for example customers in one and orders in another. A join combines them using a shared column such as a customer ID. The three joins below cover most situations you will meet.

Diagram of inner, left and full joins using overlapping circles
Inner, left and full joins differ in which rows they keep.

How to practise

Pick a small dataset you understand, such as a sales or attendance sheet, load it into a practice database and write five questions you would like answered. Turn each into a query. Checking your result against what you expected is the quickest way to learn.

Key takeaways

  • Most queries are built from SELECT, FROM, WHERE, GROUP BY and ORDER BY.
  • Read and write them in the order you would explain the question.
  • Joins combine tables through a shared column.
  • Practise with questions you already know the answers to.

Want to learn SQL properly?

Our SQL for Data Professionals course takes you from first query to joins and analysis with trainer feedback.

Enquire about SQL training

Leave a Reply

Your email address will not be published. Required fields are marked *