Loading topic
UNION, INTERSECT, and EXCEPT. This chapter gives you the working model they all share. Later chapters cover each operator, NULL handling, ordering, precedence, and dialect differences in7 min readUNION stacks the rows of two queries into one result and removes duplicate rows from the combined output. This chapter assumes you can write SELECT queries with WHERE, you know what DISTINCT and ORDER BY do, and you know that NULL means "no value". The earlier chapters covered union comp6 min readSELECT queries with WHERE, you know what DISTINCT does, and you have read the previous chapters on union compatibility and UNION. Here you will see what UNION ALL does differently, why that makes it the better default for many queries, and which mistakes 7 min readSELECT queries with WHERE, that you know DISTINCT and ORDER BY, and that you know a NULL means "no value". It also assumes you have seen why two queries must have compatible column lists before a set operator can combine them. INTERSECT takes two query 6 min readEXCEPT operator. It assumes you can write basic SELECT queries with WHERE, that you know what DISTINCT does, and that you have read the earlier chapters on union compatibility, UNION, and INTERSECT. You should also know that NULL means "unknown or missing value"7 min readORDER BY and row limiting work when a query uses UNION, INTERSECT, or EXCEPT. It assumes you can write basic SELECT queries with WHERE, you know DISTINCT and ORDER BY on a single query, and you know that a NULL represents a missing value. You should also kno6 min readINTERSECT and EXCEPT have close relatives written with joins and EXISTS. This chapter shows the rewrites, where each one differs from the set operator, and how to pick one. It assumes you can write JOIN, LEFT JOIN, and correlated subqueries. It also assumes you know that NULL = NULL is n5 min readINTERSECT ALL and EXCEPT ALL.6 min readUNION, INTERSECT, and EXCEPT queries, know how DISTINCT works, and have read an execution plan at least once. It covers what set operators cost, when to pick a cheaper form, and how to check your choice in your own database.7 min readUNION, INTERSECT, and EXCEPT. Real databases follow it closely for UNION and UNION ALL. They differ more on INTERSECT, EXCEPT, the ALL variants, precedence, and what the parser accepts around the operators. This chapter assumes7 min read