MySQL + SQL · Lesson 114
50 Important MySQL Queries
Practice Queries (Set 1)
Practice these on a
students(roll_no, name, class, marks, city) table. Try writing each before checking.Basic SELECT & WHERE
1. SELECT * FROM students;
2. SELECT name, marks FROM students;
3. SELECT * FROM students WHERE marks >= 90;
4. SELECT * FROM students WHERE class = '10';
5. SELECT * FROM students WHERE marks BETWEEN 60 AND 80;
6. SELECT * FROM students WHERE name LIKE 'A%';
7. SELECT * FROM students WHERE city IN ('Delhi','Agra');
8. SELECT DISTINCT class FROM students;
9. SELECT * FROM students ORDER BY marks DESC;
10. SELECT * FROM students ORDER BY marks DESC LIMIT 3;
Aggregates & Grouping
11. SELECT COUNT(*) FROM students;
12. SELECT AVG(marks) FROM students;
13. SELECT MAX(marks), MIN(marks) FROM students;
14. SELECT class, COUNT(*) FROM students GROUP BY class;
15. SELECT class, AVG(marks) FROM students GROUP BY class HAVING AVG(marks)>75;
Modifying Data
16. INSERT INTO students VALUES (51,'New','10',88,'Agra');
17. UPDATE students SET marks=95 WHERE roll_no=1;
18. DELETE FROM students WHERE marks<33;
19. SELECT name, CASE WHEN marks>=33 THEN 'Pass' ELSE 'Fail' END AS res FROM students;
20. SELECT class, COUNT(*) FROM students GROUP BY class ORDER BY 2 DESC;
More to Try
21–50: count students per city, find the topper of each class (window functions), students with no city (IS NULL), second-highest mark (LIMIT 1 OFFSET 1), and joins with a fees table. Build these on your own for full practice.
Summary
- Covers SELECT, WHERE, ORDER, LIMIT, aggregates, GROUP BY/HAVING, INSERT/UPDATE/DELETE, CASE.
- Write each query yourself first, then verify the output.