Incorrect:
WHERE city = Pune;
Correct:
WHERE city = 'Pune';
❌ Mistake 3: Using AND when you mean OR
Incorrect if you want either city:
WHERE city = 'Pune'
AND city = 'Mumbai';
A single city value cannot normally be both at the same time.
Correct:
WHERE city = 'Pune'
OR city = 'Mumbai';
Or:
WHERE city IN ('Pune', 'Mumbai');❌ Mistake 4: Forgetting parentheses
For complex conditions, use parentheses:
WHERE
(city = 'Pune' OR city = 'Mumbai')
AND age > 30;
❌ Mistake 5: Assuming BETWEEN excludes the boundaries
BETWEEN is generally inclusive.
🔹 34. Interview Questions
💡 What is the purpose of WHERE?
WHERE filters rows based on a condition.
💡 What is the difference between WHERE and SELECT?
SELECT → Determines what columns/expressions appear in the result.
WHERE → Determines which rows are included.
💡 How do you check for NULL?
Use:
IS NULL
or:
IS NOT NULL
💡 What is the difference between IN and OR?
IN provides a concise way to test whether a value matches any value in a list.
💡 Is BETWEEN inclusive?
Yes, BETWEEN generally includes both boundary values.
🎯 Practice Questions
Q1. Write a query to retrieve employees whose salary is greater than 50,000.
Q2. Write a query to retrieve customers from Pune or Mumbai.
Q3. Write a query to retrieve products priced between 1,000 and 5,000.
Q4. Write a query to retrieve customers whose phone number is missing.
Q5. Write a query to retrieve orders where the status is Success and the amount is greater than 10,000.
🎯 Key Takeaways
✅ WHERE is used to filter rows.
✅ = checks equality.
✅ <> and != can be used for not equal.
✅ AND requires all specified conditions to be true.
✅ OR requires at least one condition to be true.
✅ IN is useful for matching multiple values.
✅ BETWEEN is useful for ranges and is generally inclusive.
✅ LIKE is used for pattern matching.
✅ % represents a sequence of characters.
✅ _ represents one character.
✅ Use IS NULL and IS NOT NULL for NULL values.
✅ Parentheses make complex AND/OR logic clearer and safer.
🧭 Double Tap ❤️ For More