SQL Quiz & Exercises π
Mentor's Note: Reading is good, but doing is better. Try to solve these problems without looking at the reference hub. If you can solve all 5, you are ready for your college exams! π‘
π Part 1: Multiple Choiceβ
Q1. Which clause is used to filter groups after they have been aggregated?β
- A) WHERE
- B) ORDER BY
- C) HAVING
- D) DISTINCT
Q2. What is the result of 10 + NULL in SQL?β
- A) 10
- B) 0
- C) Error
- D) NULL
π» Part 2: Practical Challengesβ
Challenge 1: The High Rollers π°β
Problem: Find all employees who earn more than βΉ60,000 and sort them by name alphabetically.
View Solution
SELECT * FROM employees
WHERE salary > 60000
ORDER BY name ASC;
Challenge 2: The Missing Email π§β
Problem: Count how many students have not provided an email address.
View Solution
SELECT COUNT(*)
FROM students
WHERE email IS NULL;
Challenge 3: The Multi-Table Match πΈοΈβ
Problem: Show the emp_name and the dept_name for every employee using an INNER JOIN.
View Solution
SELECT E.emp_name, D.dept_name
FROM employees E
JOIN departments D ON E.dept_id = D.id;
π Self-Assessmentβ
- 0-2 Correct: Go back to Foundations. πΆ
- 3-4 Correct: Good progress! Review Joins. π§
- 5 Correct: SQL Master! Move to PL/SQL. π
π‘ Pro Tip: "Consistency is what transforms average into excellence. Practice one query every day!"