Practice Ideas
Hands-On Practice Exercises
Overview: The best way to master SQL is through consistent practice. These exercises are designed to reinforce the core concepts you have learned, from basic table creation to advanced subqueries and joins.
Goal: Complete these tasks to build "muscle memory" for SQL syntax. By the end of these exercises, you will have a functional database and the skills to extract meaningful insights from it.
Level 1: The Basics (Table Management)
Task 1: Create a table named students with columns for id (Primary Key), name, age, and city.
Task 2: Use the INSERT INTO statement to add at least 5 sample records with varying ages and cities.
Level 2: Filtering and Sorting
Task 3: Write a query to display all students who live in Bengaluru.
Task 4: Retrieve all student records and sort them by age from highest to lowest (Descending order).
Task 5: Practice conditional logic—write a query that filters students based on multiple "IF style" conditions (e.g., students older than 18 AND living in a specific city).
Level 3: Aggregation and Grouping
Task 6: Generate a summary report showing the count of how many students belong to each city. (Hint: Use GROUP BY).
Task 7: Modify the previous query to only show cities that have more than 2 students (Hint: Use HAVING).
Level 4: Advanced Connectivity
Task 8: Create a second table called courses and a joining table called enrollments. Write an INNER JOIN to show a list of student names alongside the courses they are enrolled in.
Task 9: Write a subquery to find and display only the students who are older than the average age of the entire class.
Self-Check Table
| Skill Tested | SQL Keywords to Use |
|---|---|
| Data Organization | ORDER BY age DESC |
| Data Summarization | COUNT(*), GROUP BY |
| Relational Logic | INNER JOIN ... ON |
| Dynamic Filtering | WHERE column > (SELECT ...) |
Key Tips for Success
- Small Steps: Don't try to write a 10-line query all at once. Start with a basic
SELECT *and add filters or joins one by one to ensure each part works. - Analyze Errors: If the query fails, read the error message carefully. It usually tells you exactly which line or keyword (like a missing comma or quote) is causing the problem.
- Verify Results: Always look at the data returned. Does it actually answer the question you asked? If you sorted by age, is the oldest student really at the top?
🏋️ Test Yourself With Exercises
Take our quiz on Practice Ideas to test your knowledge.
Browse Quizzes »