7. Using Comparison Operators
Idea: =, >, <, >=, <=, <> compare values in WHERE.
Shape
SELECT * FROM TableName WHERE Price > 100;
Multiple Operators
WHERE Name = 'Amit' OR Age < 30
Placeholders for Examples
Coming soon: comparing product prices and names.
Advanced Deep Dive ADVANCED
Data Types: Comparisons work differently for text, numbers, dates. Implicit conversions can cause errors or slow queries.
NULLs: = NULL never matches; use IS NULL or IS NOT NULL.
Collation: Text comparisons depend on collation; case and accent sensitivity matter.
Predicate Selectivity: Highly selective comparisons (few matches) are faster with indexes.
Non-SARGable: Avoid WHERE YEAR(DateCol) = 2024; use WHERE DateCol >= '2024-01-01' AND DateCol < '2025-01-01' for index usage.