Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSQLUNION vs UNION ALLSingle-choice MCQ

Two SELECTs are combined with UNION (not UNION ALL). Both inputs are already sorted by id. Why can UNION still be much slower than UNION ALL here?

SELECT id FROM a UNION SELECT id FROM b;