SQL SELECT Statement Explained with Examples
If you're beginning your SQL journey, the SELECT statement is the very first command you should learn.
Almost every SQL query starts with SELECT because it is used to retrieve data from a database.
In this beginner-friendly guide by DataWithAnmol, you'll learn how the SELECT statement works with simple examples.
What is the SQL SELECT Statement?
The SELECT statement is used to retrieve data from one or more tables in a database.
Think of a database as a library.
The SELECT command helps you find exactly the books (data) you need.
Basic Syntax
SELECT column_name
FROM table_name;
Example Table
Imagine we have an Employees table.
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 101 | Amit | HR | 50000 |
| 102 | Neha | IT | 65000 |
| 103 | Raj | IT | 48000 |
| 104 | Priya | Sales | 72000 |
| 105 | Ravi | Finance | 60000 |
Select All Columns
SELECT *
FROM Employees;
The asterisk (*) means "retrieve every column."
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 101 | Amit | HR | 50000 |
| 102 | Neha | IT | 65000 |
| 103 | Raj | IT | 48000 |
| 104 | Priya | Sales | 72000 |
| 105 | Ravi | Finance | 60000 |
Select Specific Columns
Instead of retrieving everything, you can choose only the columns you need.
SELECT Name, Salary
FROM Employees;
| Name | Salary |
|---|---|
| Amit | 50000 |
| Neha | 65000 |
| Raj | 48000 |
| Priya | 72000 |
| Ravi | 60000 |
This makes your queries faster and easier to understand.
Rename Column Using AS
You can change the display name of a column.
SELECT Name AS Employee_Name,
Salary AS Monthly_Salary
FROM Employees;
| Employee_Name | Monthly_Salary |
|---|---|
| Amit | 50000 |
| Neha | 65000 |
| Raj | 48000 |
| Priya | 72000 |
| Ravi | 60000 |
Remove Duplicate Values
Use the DISTINCT keyword.
SELECT DISTINCT Department
FROM Employees;
- HR
- IT
- Sales
- Finance
Each department appears only once.
Common Mistakes Beginners Make
❌ Forgetting the FROM clause:
SELECT Name;
Correct Alignment:
SELECT Name
FROM Employees;
❌ Using SELECT * when only one or two columns are needed:
Fetching only the required columns significantly improves query performance.
Real-World Example
Imagine your manager asks:
"Show me the names and salaries of all employees."
The SQL query would be:
SELECT Name, Salary
FROM Employees;
Simple, fast, and exactly what the manager needs.
Key Takeaways
-
SELECTretrieves data from a table. -
*returns all columns. You can select specific columns.
-
ASrenames columns in the output. -
DISTINCTremoves duplicate values. Using only required columns improves efficiency.
What's Next?
Now that you've learned the SELECT statement, the next topic is WHERE, which allows you to filter records based on conditions.
Stay connected with DataWithAnmol for more beginner-friendly SQL tutorials, practice questions, and Data Analytics learning resources.
📺 YouTube: https://youtube.com/@datawithanmolofficial?si=8APtSK5TY6Tl9Xd_
Suggested internal links for your blog
At the end of this post, add links to:
-
SQL WHERE Clause Explained (next article)
About DataWithAnmol
Hi! I'm Anmol Raj, founder of DataWithAnmol.
My goal is to make Data Analytics easy for beginners through practical tutorials, SQL challenges, Power BI projects, Excel tips, and career guidance.
You can also learn with me on YouTube:
DataWithAnmol
https://youtube.com/@datawithanmolofficial?si=8APtSK5TY6Tl9Xd_
Meta Description:
Learn the SQL SELECT statement with simple examples. Understand how to retrieve data from a database using SQL. Perfect for beginners learning SQL with DataWithAnmol.
Comments
Post a Comment