SQL is one of the most essential skills for every computer science student. Whether you are preparing for placements, working on projects, or becoming a backend/full-stack developer, mastering SQL helps you think logically and handle real-world data confidently. Here are the top 20 SQL queries every student must practice to build a strong foundation:

1. Create a Table

CREATE TABLE Students (id INT, name VARCHAR(50), age INT);

2. Insert Data

INSERT INTO Students VALUES (1, 'Arun', 20);

3. Select All Records

SELECT * FROM Students;

4. Select Specific Columns

SELECT name, age FROM Students;

5. WHERE Condition

SELECT * FROM Students WHERE age > 18;

6. UPDATE Query

UPDATE Students SET age = 21 WHERE id = 1;

7. DELETE Query

DELETE FROM Students WHERE id = 1;

8. ORDER BY

SELECT * FROM Students ORDER BY age DESC;

9. DISTINCT Values

SELECT DISTINCT age FROM Students;

10. COUNT(), MAX(), MIN(), AVG(), SUM()

SELECT COUNT(*), AVG(age) FROM Students;

11. GROUP BY

SELECT age, COUNT(*) FROM Students GROUP BY age;

12. HAVING Clause

SELECT age, COUNT(*) 
FROM Students 
GROUP BY age 
HAVING COUNT(*) > 1;

13. LIKE Operator

SELECT * FROM Students WHERE name LIKE 'A%';

14. IN Operator

SELECT * FROM Students WHERE age IN (18, 19, 20);

15. BETWEEN

SELECT * FROM Students WHERE age BETWEEN 18 AND 22;

16. INNER JOIN

SELECT s.name, c.course 
FROM Students s 
JOIN Courses c ON s.id = c.student_id;

17. LEFT JOIN

SELECT s.name, c.course 
FROM Students s 
LEFT JOIN Courses c ON s.id = c.student_id;

18. SUBQUERY (Nested Query)

SELECT name FROM Students 
WHERE age > (SELECT AVG(age) FROM Students);

19. CREATE VIEW

CREATE VIEW StudentView AS 
SELECT name, age FROM Students;

20. ALTER TABLE

ALTER TABLE Students ADD email VARCHAR(50);

Comments

Popular posts from this blog

Why Version Control (Git & GitHub) Is a Must for Every Student

Simple Ways to Understand Normal Forms with Daily Life Examples