SELECT
SELECT is the statement you will write more than any other. It reads data and returns it as a result set.
On this page · 5 min · Beginner
On this page
- In simple words
- Learning objectives
- Explanation
- Syntax
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 27, 2026
Related tutorials
In simple words#
SELECT is asking the office clerk: “Show me the name and phone columns from the Students register.” You choose which columns to see.
- SELECT
- Choose columns to read.
- FROM
- Which table to read from.
- Alias (AS)
- A temporary nickname for a column or table.
Learning objectives#
- Select specific columns
- Rename columns with aliases
- Return unique values with DISTINCT
- Limit rows with TOP
Explanation#
SELECT lists the columns (or expressions) you want; FROM says which table to read.
AS gives a column a friendly name in the result — useful for calculated values.
DISTINCT removes duplicate rows from the result. TOP (n) returns only the first n rows — always pair it with ORDER BY, otherwise “first” is not defined.
Syntax#
SELECT [DISTINCT] [TOP (n)] column1, expression AS Alias
FROM TableName
[ORDER BY column];
Code example: The three most expensive products#
SELECT TOP (3) Name AS Product, Category, Price
FROM Products
ORDER BY Price DESC;
SELECT DISTINCT Category
FROM Products
ORDER BY Category;
Product Category Price Laptop Electronics 55000.00 Desk Furniture 12000.00 Chair Furniture 4500.00 Category Electronics Furniture Stationery
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- The first query sorts all products by price, highest first, and keeps the top three.
- Name AS Product renames the column in the output only — the table is unchanged.
- The second query returns each category once, even though each appears twice in the table.
Real-world use case#
“Top 10 best-selling products” on a shop homepage is a SELECT TOP with ORDER BY.
Common mistakes#
It returns columns you do not need, breaks when columns are added, and prevents covering indexes. List the columns.
Without ORDER BY, SQL Server may return any rows, and the result can change between runs.
Best practices#
- Name the columns you need
- Use clear aliases for calculated columns
- Always use ORDER BY with TOP
- Format queries one clause per line
Remember this#
SELECT columns FROM table.
Avoid SELECT * in applications.
AS gives a column a friendly name.
Practice exercise#
Your task: Return the two cheapest products with their price, using an alias Cost for Price.
Show solution
SELECT TOP (2) Name, Price AS Cost FROM Products ORDER BY Price; -- Pen 20.00, Notebook 60.00
Mini quiz#
What does DISTINCT do?
Want more? Practise all SQL Server MCQs · SQL Server interview questions
My notes#
Saved in this browser.