SQL Query Performance - Which One To Choose SQL OR Operator Or UNION ON operator

Manish Sharma · Advanced ·📊 Data Analytics & Business Intelligence ·1mo ago
Follow @RebellionRider for more SQL interview questions. Interviewer: Why does using OR in WHERE slow down SQL compared to UNION ALL? Here’s the blunt truth. OR confuses the optimizer. When you write: WHERE col1 = 10 OR col2 = 20 The database often cannot use indexes efficiently. It may ignore both indexes. It may switch to a full table scan. Because it has to evaluate multiple conditions per row and combine them. Now look at UNION ALL. You split the logic into two clean queries. Each query can use its own index. Each query can get its own optimal execution plan. Then the results are s…
Watch on YouTube ↗ (saves to browser)
AI Powered Business Analytics With Excel Full Course | Excel For Business Analytics | Simplilearn
Next Up
AI Powered Business Analytics With Excel Full Course | Excel For Business Analytics | Simplilearn
Simplilearn