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


π§ 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
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.