SQL SELECT Statement – Complete Beginner's Guide with Examples (2026)
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.
✅ Basic Example – Table called Employees
| EmployeeID | FirstName | LastName | Department |
|---|---|---|---|
| 1 | Pramod | Behera | IT |
| 2 | Pooja | Shinde | HR |
✅ SELECT Query:-
SELECT FirstName, LastName FROM Employees;
✅ Result:-
| FirstName | LastName |
|---|---|
| Pramod | Behera |
| Pooja | Shinde |
✅ Example – SELECT All Columns
✅ SELECT Query:-
SELECT * FROM Employees;
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';
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;
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 rows | SELECT COUNT(*) FROM Employees; |
SUM() | Add up values in a column | SELECT SUM(Salary) FROM Employees; |
AVG() | Calculate average value | SELECT AVG(Salary) FROM Employees; |
MAX() | Find highest value | SELECT MAX(Salary) FROM Employees; |
MIN() | Find lowest value | SELECT MIN(Salary) FROM Employees; |
✅ Example – Count employees per department using GROUP BY:-
SELECT Department, COUNT(*) AS TotalEmployees
FROM Employees
GROUP BY Department;
✅ Result:-
| Department | TotalEmployees |
|---|---|
| IT | 1 |
| HR | 1 |
GROUP BY when you want results per category (e.g. per department, per city, per product).
✅ Common Clauses Used with SELECT
| Clause | Purpose | Example |
|---|---|---|
WHERE | Filter rows | WHERE Salary > 50000 |
ORDER BY | Sort the result | ORDER BY Name ASC |
GROUP BY | Group rows (used with aggregates) | GROUP BY Department |
HAVING | Filter grouped rows | HAVING COUNT(*) > 1 |
LIMIT | Limit the number of returned rows | LIMIT 10 |
DISTINCT | Return unique values only | SELECT DISTINCT Dept |
✅ Common SQL SELECT Mistakes to Avoid
Fetching all columns slows down queries on large tables. Always name only the columns you need.
Wrong:
WHERE Department = IT — will cause an error.Correct:
WHERE Department = 'IT'
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.
Use
WHERE to filter individual rows. Use HAVING to filter groups after GROUP BY.
✅ Frequently Asked Questions (FAQ)
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.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.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.