🔹 WHERE Clause
Definition: The WHERE
clause is used to filter records. It fetches only those rows that meet a specified condition.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
🎓 Sample Table: students
id | name | age | grade |
1 | Asha | 15 | A |
2 | Rohan | 14 | B |
3 | Meena | 16 | A |
4 | Vikram | 15 | C |
SELECT * FROM students WHERE grade = 'A';
🟢 Output: Returns students who scored grade A.
id | name | age | grade |
1 | Asha | 15 | A |
3 | Meena | 16 | A |
SELECT name FROM students WHERE age > 14;
🟢 Output: Shows names of students older than 14.
📌 When to Use WHERE:
Use the WHERE
clause when you want to retrieve only specific records based on a condition (e.g., grade = 'A' or age > 15).
⚠️ Common Mistakes:
- Using = for numeric comparisons without quotes — works fine, but avoid quotes for numbers.
- Forgetting to wrap string values in single quotes (e.g.,
grade = A
instead of grade = 'A'
).
- Misspelled column names.