SQL Tutorial

SQL SELECT Statement – Complete Beginner's Guide with Examples (2026)

By Pramod Behera  ·  Updated:  ·  Reading time: 8 min

SQL SELECT statement is the most important SQL command used to query and retrieve data from a relational database. In this beginner-friendly guide, you will learn the SQL SELECT syntax with real examples — including how to use WHERE, ORDER BY, GROUP BY, DISTINCT and LIMIT clauses - plus aggregate functions, common mistakes to avoid, and FAQs answered.



✅ How to Use SQL SELECT Statement | Syntax, Examples & Tips

✅ Basic Syntax

SELECT column1, column2, ...
FROM table_name;

SQL SELECT Query-Statement

SELECT:- Keyword to specify the columns you want to retrieve.

FROM:- Specifies the table to retrieve data from.

💡 Key Point: The SELECT statement is a read-only operation. It does not insert, update, or delete any data in your database.

✅ Basic Example – Table called Employees

Employees
EmployeeID FirstName LastName Department
1PramodBeheraIT
2PoojaShindeHR

SELECT Query:-

SELECT FirstName, LastName FROM Employees;

Result:-

Result
FirstName LastName
PramodBehera
PoojaShinde

✅ Example – SELECT All Columns

SELECT Query:-

SELECT * FROM Employees;
⚠️ Best Practice: Avoid using SELECT * in production applications. It retrieves all columns, which can slow down queries on large tables. Always specify only the columns you actually need.

✅ Example – Using WHERE Clause

The WHERE clause is used to filter rows based on a specific condition. Only rows matching the condition are returned. For more advanced filtering, see our complete SQL WHERE Clause guide.

SELECT Query:-

SELECT * FROM Employees
WHERE Department = 'IT';
💡 Tip: Combine conditions using AND and OR.
Example: WHERE Department = 'IT' AND Salary > 70000

✅ Example – Ordering Results with ORDER BY

The ORDER BY clause sorts results by a column. Use ASC for ascending (A–Z, 0–9) or DESC for descending (Z–A, 9–0).

SELECT Query:-

SELECT * FROM Employees
ORDER BY LastName ASC;

✅ Example – Limit Rows with LIMIT

The LIMIT clause restricts how many rows are returned. Useful for previewing data or getting top N records. See also our SQL TOP / LIMIT / FETCH FIRST guide for database-specific syntax.

SELECT Query:-

SELECT * FROM Employees
LIMIT 5;
💡 Note: LIMIT works in MySQL, PostgreSQL, SQLite. In SQL Server use TOP. In Oracle use FETCH FIRST n ROWS ONLY.

✅ SELECT with Aggregate Functions

SQL SELECT is commonly used with aggregate functions to perform calculations on groups of rows. These are essential for data analysis and reporting tasks.

Function Description Example Query
COUNT()Count number of rowsSELECT COUNT(*) FROM Employees;
SUM()Add up values in a columnSELECT SUM(Salary) FROM Employees;
AVG()Calculate average valueSELECT AVG(Salary) FROM Employees;
MAX()Find highest valueSELECT MAX(Salary) FROM Employees;
MIN()Find lowest valueSELECT MIN(Salary) FROM Employees;

Example – Count employees per department using GROUP BY:-

SELECT Department, COUNT(*) AS TotalEmployees
FROM Employees
GROUP BY Department;

Result:-

DepartmentTotalEmployees
IT1
HR1
💡 Tip: Always pair aggregate functions with GROUP BY when you want results per category (e.g. per department, per city, per product).

✅ Common Clauses Used with SELECT

Clause Purpose Example
WHEREFilter rowsWHERE Salary > 50000
ORDER BYSort the resultORDER BY Name ASC
GROUP BYGroup rows (used with aggregates)GROUP BY Department
HAVINGFilter grouped rowsHAVING COUNT(*) > 1
LIMITLimit the number of returned rowsLIMIT 10
DISTINCTReturn unique values onlySELECT DISTINCT Dept

✅ Common SQL SELECT Mistakes to Avoid

❌ Mistake 1: Using SELECT * in production
Fetching all columns slows down queries on large tables. Always name only the columns you need.
❌ Mistake 2: Forgetting quotes around string values
Wrong: WHERE Department = IT — will cause an error.
Correct: WHERE Department = 'IT'
❌ Mistake 3: Wrong clause order
SQL clauses must follow this exact order: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT. Writing them out of order causes a syntax error.
❌ Mistake 4: Confusing WHERE and HAVING
Use WHERE to filter individual rows. Use HAVING to filter groups after GROUP BY.

✅ Frequently Asked Questions (FAQ)

What is the SQL SELECT statement?
The SQL SELECT statement is used to retrieve data from one or more tables in a relational database. It is a read-only operation — it does not modify, delete, or insert any data. It is the most commonly used SQL command.
What does SELECT * mean in SQL?
SELECT * means select all columns from the specified table. While convenient for quick lookups, it is not recommended for production code as it can slow down performance on large tables.
What is the difference between WHERE and HAVING in SQL?
WHERE filters rows before grouping. HAVING filters rows after a GROUP BY clause. Use WHERE for individual row conditions and HAVING for group-level conditions.
What is the correct order of SQL clauses?
The correct order is: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT. Writing them in the wrong order will cause a syntax error.
How do I select only unique values in SQL?
Use SELECT DISTINCT to return only unique values. Example: SELECT DISTINCT Department FROM Employees; — returns each department name only once. Learn more in our SQL SELECT DISTINCT guide.
Is SQL SELECT important for beginners?
Yes, the SELECT statement is the most important SQL command because it is used to fetch and analyze data from databases. Every SQL learner must master it first.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.