Open the app

← All guides

SQL for beginners: SELECT, SUM and GROUP BY

SQL is the standard language for asking questions of a table. A few keywords cover most business questions.

The four keywords

SELECT chooses the columns you want to see. FROM names the table. GROUP BY makes one row per group, such as per city. ORDER BY sorts the result. Functions like SUM and COUNT calculate totals and counts.

An example

To see money by city, biggest first, you write: SELECT city, SUM(amount) AS money FROM sales GROUP BY city ORDER BY money DESC. Read it aloud: show each city and the sum of amount, from the sales table, one row per city, biggest first.

Practise safely

Reading data never changes it, so you can experiment. Change the column names and see what happens. Add LIMIT 5 to see only the top five rows.

In Super B.A.: SQL Studio and the Learn & Lab mini-projects let you run queries on your own table. Open the app

Related guides

General information for learning. It is not financial, tax, legal or investment advice.