10 Essential SQL Queries Every Beginner Should Know (With Examples)

Rohit KumarRohit Kumar
2 min read

🧠 What Is SQL?

SQL (Structured Query Language) is the language used to interact with relational databases. Whether you're a software developer, data analyst, or even a beginner coder, SQL helps you fetch, filter, and manipulate data with ease.


πŸ“‹ Let’s Dive into the 10 Must-Know SQL Queries:

πŸ“Œ Assume we’re using a sample table called employees:

| id | name      | department | salary |
|----|-----------|------------|--------|
| 1  | Rohit     | Tech       | 50000  |
| 2  | Anjali    | HR         | 45000  |
| 3  | Sameer    | Tech       | 60000  |
| 4  | Priya     | Finance    | 40000  |

πŸ”Ή 1. SELECT – Get Data from a Table

SELECT * FROM employees;

Fetches all columns and rows from the table.


πŸ”Ή 2. WHERE – Filter Records

SELECT * FROM employees WHERE department = 'Tech';

Returns only employees in the Tech department.


πŸ”Ή 3. ORDER BY – Sort Results

SELECT * FROM employees ORDER BY salary DESC;

Sorts employees by salary in descending order.


πŸ”Ή 4. LIMIT – Return Top N Rows

SELECT * FROM employees ORDER BY salary DESC LIMIT 2;

Returns top 2 highest paid employees.


πŸ”Ή 5. COUNT – Total Number of Records

SELECT COUNT(*) FROM employees;

Returns total number of employees.


πŸ”Ή 6. GROUP BY – Aggregate by Category

SELECT department, COUNT(*) FROM employees GROUP BY department;

Shows number of employees in each department.


πŸ”Ή 7. AVG / SUM – Calculate Values

SELECT AVG(salary) FROM employees;
SELECT SUM(salary) FROM employees;

Gives average and total salary respectively.


πŸ”Ή 8. LIKE – Pattern Matching

SELECT * FROM employees WHERE name LIKE 'S%';

Finds names starting with 'S'.


πŸ”Ή 9. IN – Match Multiple Values

SELECT * FROM employees WHERE department IN ('Tech', 'HR');

Returns employees from Tech or HR.


πŸ”Ή 10. JOIN – Combine Data from Two Tables

πŸ“Œ Assume a second table:

projects (id, employee_id, project_name)

Join them:

SELECT employees.name, projects.project_name
FROM employees
JOIN projects ON employees.id = projects.employee_id;

Displays each employee with their project.

πŸ’¬ Have questions or got stuck while following this guide?

Drop your doubts in the comments β€” I’d love to help you out!

β€” ✍️ Written by Rohit @ TechWithRohit

0
Subscribe to my newsletter

Read articles from Rohit Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Kumar
Rohit Kumar

πŸ‘¨β€πŸ’» Working IT professional | ✍️ Beginner-friendly tech writer I simplify tools like Git, SQL, and developer workflows so that even total beginners can get started with confidence. πŸš€ On a mission to break down complex tech into easy steps β€” one blog at a time. πŸ“š Topics I write about: Git, GitHub, SQL, Dev tools, Productivity for new developers πŸ’‘ Let’s grow together β€” follow for simple, clear, no-fluff tutorials.