SQL Tutorial · Chapter 3 of 32
The SQL SELECT statement retrieves data from one or more tables and returns it as a result set of rows and columns. You name the columns you want after SELECT and the table after FROM. It is the most used command in SQL: nearly every report, dashboard and analysis starts with a SELECT query.
This chapter is for beginners learning SQL and for spreadsheet users moving their data into a database. You will learn the SELECT syntax, how to return specific or all columns, how to add calculated and text columns, and how to avoid the mistakes that trip up most new users. Every example runs against two small sample tables and shows the exact output.
SQL SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
-- all columns
SELECT * FROM table_name;
The column list controls which columns come back and in what order. The asterisk * is shorthand for every column in the table.
| Part | What it means |
|---|---|
SELECT |
Starts the query and lists what to return |
column1, column2 |
The columns to return, separated by commas, in the order you want them |
* |
Every column in the table, in the order the table defines them |
expression AS name |
A calculated value (for example Amount * 1.18) with a readable column name |
FROM table_name |
The table (or tables) the data comes from |
; |
Ends the statement; required when you run several statements together |
Sample Tables
| CustomerID | Name | City | Country |
|---|---|---|---|
| 1 | Anita Sharma | Mumbai | India |
| 2 | John Smith | London | UK |
| 3 | Maria Garcia | Madrid | Spain |
| 4 | Wei Chen | Singapore | Singapore |
| 5 | Emma Brown | Sydney | Australia |
| OrderID | CustomerID | Product | Amount | OrderDate |
|---|---|---|---|---|
| 101 | 1 | Laptop | 1200 | 2026-01-05 |
| 102 | 2 | Mouse | 25 | 2026-01-07 |
| 103 | 1 | Monitor | 300 | 2026-01-12 |
| 104 | 3 | Keyboard | 45 | 2026-02-02 |
| 105 | 6 | Headset | 80 | 2026-02-15 |
| 106 | 4 | Laptop | 1150 | 2026-03-01 |
Example 1: Select Specific Columns
SELECT Name, Country
FROM Customers;
| Name | Country |
|---|---|
| Anita Sharma | India |
| John Smith | UK |
| Maria Garcia | Spain |
| Wei Chen | Singapore |
| Emma Brown | Australia |
Only the two named columns are returned, in the order you listed them, for all five rows.
Example 2: Select All Columns
SELECT * FROM Orders;
This returns the complete Orders table shown above: six rows and five columns. SELECT * is handy for exploring a table, but in saved queries list the columns explicitly so the result does not change when someone adds a column.
Example 3: Calculated Columns
SELECT can return expressions, not just stored columns. Here we add 18% tax to each order amount and name the new column with an alias.
SELECT OrderID, Amount, Amount * 1.18 AS AmountWithTax
FROM Orders;
| OrderID | Amount | AmountWithTax |
|---|---|---|
| 101 | 1200 | 1416.00 |
| 102 | 25 | 29.50 |
| 103 | 300 | 354.00 |
| 104 | 45 | 53.10 |
| 105 | 80 | 94.40 |
| 106 | 1150 | 1357.00 |
The number of decimal places shown depends on the database; the values are the same.
Example 4: Text Expressions
SELECT Name, City || ', ' || Country AS Location
FROM Customers;
| Name | Location |
|---|---|
| Anita Sharma | Mumbai, India |
| John Smith | London, UK |
| Maria Garcia | Madrid, Spain |
| Wei Chen | Singapore, Singapore |
| Emma Brown | Sydney, Australia |
|| is the standard concatenation operator; see the dialect notes below for MySQL and SQL Server.
Example 5: SELECT Without a Table
SELECT 7 * 6 AS Answer;
| Answer |
|---|
| 42 |
Useful for testing functions and expressions. Older Oracle versions need FROM DUAL for this form.
Example 6: SELECT with a Filter and a Sort
In real queries SELECT rarely works alone. Adding WHERE limits the rows and ORDER BY sorts them; both are covered in their own chapters, but here is a preview.
SELECT Product, Amount
FROM Orders
WHERE Amount > 50
ORDER BY Amount DESC;
| Product | Amount |
|---|---|
| Laptop | 1200 |
| Laptop | 1150 |
| Monitor | 300 |
| Headset | 80 |
The Mouse (25) and Keyboard (45) orders are filtered out, and the rest are sorted from largest to smallest. Learn the filter in detail in the SQL WHERE chapter.
Practical Variations
- Rename columns for a report:
SELECT Name AS Customer, City AS "Home City" FROM Customers;Use double quotes (or square brackets in SQL Server) for names with spaces. - Qualify column names:
SELECT Customers.Name FROM Customers;This becomes essential once a query uses two tables that share a column name. - Add a constant column:
SELECT Name, 'Active' AS Status FROM Customers;returns “Active” on every row, useful when combining results. - Return only a few rows while exploring: add
LIMIT 5(MySQL, PostgreSQL, SQLite) or useSELECT TOP 5(SQL Server). The SQL TOP, LIMIT and FETCH FIRST chapter covers this in detail.
Works in MySQL, SQL Server, PostgreSQL, SQLite
- Concatenation:
||works in PostgreSQL, SQLite and Oracle. MySQL usesCONCAT(City, ', ', Country); SQL Server uses+orCONCAT(). - Integer division:
7 / 2returns 3 in SQL Server, PostgreSQL and SQLite but 3.5000 in MySQL. Write7.0 / 2when you want a decimal result everywhere. - Quoting names: standard SQL and PostgreSQL use
"double quotes", MySQL uses`backticks`and SQL Server uses[square brackets]for names with spaces.
How the Database Processes a SELECT
Although you write SELECT first, the database evaluates it almost last. The logical order is FROM (find the table), then WHERE (filter rows), GROUP BY and HAVING, then SELECT (compute the output columns), then ORDER BY and finally LIMIT. This explains two rules you will meet in later chapters: a column alias defined in SELECT can be used in ORDER BY but not in WHERE, and aggregate functions belong to the grouping stage rather than the row filter.
Knowing the order also helps with performance. Every column you leave out of the SELECT list is data the database does not have to read or send over the network, which is the practical reason to avoid SELECT * in reports and applications.
Common Errors and Fixes
| Problem | Why it happens | Fix |
|---|---|---|
SELECT Name City FROM Customers; returns one column called City that contains names |
Without a comma, the second word is treated as an alias for the first column | Separate columns with commas: SELECT Name, City |
| “Unknown column” (MySQL), “Invalid column name” (SQL Server) or “column does not exist” (PostgreSQL) | A typo in the column name, or the column belongs to another table | Check the spelling and the table in FROM; run SELECT * once to see the real column names |
Using an alias in WHERE fails, e.g. WHERE AmountWithTax > 100 |
WHERE runs before SELECT, so the alias does not exist yet | Repeat the expression: WHERE Amount * 1.18 > 100 |
| A text value is treated as a column name | Text was written in double quotes, which PostgreSQL and standard SQL read as a column name | Use single quotes for text values: 'India' |
| A report breaks after a column is added to the table | The query uses SELECT * |
List the columns you need explicitly |
Tips for Writing Better SELECT Queries
- Put each column on its own line in longer queries; it makes missing commas easy to spot.
- Give every calculated column an alias so the result has a readable header.
- Use
SELECT *with a row limit while exploring, then replace it with a column list. - Write keywords in capitals (SELECT, FROM) and names in their real case; it is not required, but it makes queries easier to read.
Practice Exercise
- Return the Product and Amount of every order, with a third column showing the Amount doubled, named DoubleAmount.
- Return only the City column from Customers.
Show answers
-- 1
SELECT Product, Amount, Amount * 2 AS DoubleAmount FROM Orders;
-- 2
SELECT City FROM Customers;
-- Mumbai, London, Madrid, Singapore, Sydney
Related Chapters
- SQL SELECT DISTINCT – return unique values only
- SQL Aliases – naming calculated columns and tables
- SQL Joins Explained – selecting from more than one table
- SQL from Scratch: full course overview
If you also work with data in spreadsheets, the Excel AI Mastery: 100 Formulas course on NextGenTemplates Academy teaches the formula side of the same skills, with practice files.
Frequently Asked Questions
What does SELECT * mean in SQL?
The asterisk selects every column of the table in the order they were defined. It is convenient for exploring data, but explicit column lists are better in saved queries and application code.
Can SELECT return calculated values?
Yes. Any expression, such as Amount * 1.18, text concatenation or a function call, can appear in the SELECT list. Give it a readable name with AS.
Does SELECT change the data in the table?
No. SELECT only reads data. Changing rows requires INSERT, UPDATE or DELETE, which are covered later in this course.
Is SQL SELECT case-sensitive?
Keywords are not: select, SELECT and Select all work. Whether table names, column names and text comparisons are case-sensitive depends on the database and its settings.
How do I select data from two tables?
Use a JOIN, for example SELECT c.Name, o.Product FROM Customers c JOIN Orders o ON c.CustomerID = o.CustomerID;. The joins chapter explains INNER, LEFT, RIGHT and FULL joins.
Wrapping Up
SELECT is the foundation of every SQL query: name the columns, name the table, and add expressions and aliases to shape the result. Practise the examples above against the sample tables, then move on to filtering rows with WHERE.
Test Yourself with the Free SQL Quiz
📅 Last updated: October 2026
Chapter 3 of 32 · SQL from Scratch: all 32 chapters



