SQL SELECT Statement
The SELECT statement is the foundation of SQL.
If you want to retrieve, view, filter, or analyse data inside a database table, SELECT is the command you’ll use. Every analytics query, API validation script, or reporting logic starts with a SELECT.
This tutorial covers everything you need to know to get started.
1. What Does the SELECT Statement Do?
SELECT is used to retrieve data from one or more tables.
You can choose:
- Which columns to show
- Which rows to show
- How the data should be sorted
- Whether to remove duplicates
- Whether to apply expressions or calculations
Basic syntax:
SELECT column1, column2, ...
FROM table_name;
2. Selecting All Columns
If you want to fetch all the columns from a table, use the asterisk (*):
SELECT *
FROM Employees;
This returns every row and every column in the Employees table.
⚠️ Tip for professionals:
Avoid using SELECT * in production queries. It slows performance and returns unwanted columns. Use only the columns you actually need.
3. Selecting Specific Columns
Instead of selecting all columns, you can list only the columns you need:
SELECT FirstName, LastName, City
FROM Employees;
This makes the output cleaner and the query faster.
4. Using Column Aliases (AS)
-- Aliases let you rename output columns, making results more readable:
SELECT
FirstName AS "First Name",
Salary AS "Monthly Salary"
FROM Employees;
-- You can also skip the AS keyword:
SELECT FirstName "First Name"
FROM Employees;
Aliases are extremely useful in reporting, joins, and calculations.
5. Selecting Distinct Values (DISTINCT)
If a column contains repeated values, DISTINCT removes duplicates.
-- Example: Get unique job titles:
SELECT DISTINCT JobTitle
FROM Employees;
-- Example: Unique combinations of department and city:
SELECT DISTINCT Department, City
FROM Employees;
6. Sorting Data with ORDER BY
-- The default order is ascending (ASC). Use DESC for descending.
SELECT FirstName, LastName, Salary
FROM Employees
ORDER BY Salary DESC;
-- You can sort by multiple columns:
SELECT FirstName, LastName, City, Salary
FROM Employees
ORDER BY City ASC, Salary DESC;
7. Limiting the Number of Rows
Different databases use different keywords:
-- MySQL / PostgreSQL:
SELECT *
FROM Employees
LIMIT 5;
-- SQL Server:
SELECT TOP 5 *
FROM Employees;
-- Standard SQL:
SELECT *
FROM Employees
FETCH FIRST 5 ROWS ONLY;
8. Using Expressions in SELECT
-- You can return calculated columns:
SELECT
FirstName,
LastName,
Salary,
Salary * 12 AS AnnualSalary
FROM Employees;
-- Example: Concatenate columns:
SELECT
FirstName || ' ' || LastName AS FullName
FROM Employees;
(Some databases use CONCAT() instead.)
9. SELECT with WHERE (Preview)
-- You can apply conditions to filter rows:
SELECT *
FROM Employees
WHERE City = 'London';
You will learn all filtering conditions in the next topic (SQL WHERE).
10. A Complete Practical Example
Imagine a table:
Projects
| ProjectID | ProjectName | StartDate | Status | Budget |
| 1 | CRM Migration | 2025-01-10 | Active | 40000 |
| 2 | Mobile App Revamp | 2025-02-15 | Completed | 25000 |
| 3 | Data Lake Setup | 2025-03-01 | Active | 60000 |
-- Let’s write a useful business query:
SELECT
ProjectName AS "Project",
Budget,
Budget * 1.2 AS "Revised Budget",
Status
FROM Projects
WHERE Status = 'Active'
ORDER BY Budget DESC;
Result:
| Project | Budget | Revised Budget | Status |
| Data Lake Setup | 60000 | 72000 | Active |
| CRM Migration | 40000 | 48000 | Active |
This shows how SELECT can combine:
- Filtering
- Sorting
- Aliasing
- Expressions
11. Summary Checklist
By now, you should be able to:
✔ Use SELECT to retrieve data
✔ Fetch all or specific columns
✔ Rename columns with aliases
✔ Remove duplicates with DISTINCT
✔ Sort results using ORDER BY
✔ Limit rows depending on DB system
✔ Use basic expressions inside SELECT