SQL Practice Logo

SQLPractice Online

Level 3 - IntermediateOptimization Questions

Optimization: OR Predicate Rewrite

Choose the better query for large indexed table access, then provide final SQL. Query A: SELECT id, user_id, event_type, event_time FROM events WHERE user_id = 500 OR event_type = 'PURCHASE'; Query B: SELECT id, user_id, event_type, event_time FROM events WHERE user_id = 500 UNION ALL SELECT id, user_id, event_type, event_time FROM events WHERE event_type = 'PURCHASE' AND user_id <> 500;