Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1B8BA9FA364 for ; Fri, 15 Dec 2006 17:42:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 09802-09 for ; Fri, 15 Dec 2006 17:42:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1F1079FA2D4 for ; Fri, 15 Dec 2006 17:42:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBFLg4kd021819; Fri, 15 Dec 2006 16:42:04 -0500 (EST) To: "Aaron Bono" cc: "Postgres SQL language list" Subject: Re: Unions and Grouping In-reply-to: References: Comments: In-reply-to "Aaron Bono" message dated "Fri, 15 Dec 2006 15:15:12 -0600" Date: Fri, 15 Dec 2006 16:42:04 -0500 Message-ID: <21818.1166218924@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/122 X-Sequence-Number: 27078 "Aaron Bono" writes: > My question, what do the SQL Specifications say should happen on a Union? > Is it supposed to eliminate duplicates even WITHIN the individual queries > that are being unioned? Yes. SQL92 7.10 saith: b) If a set operator is specified, then the result of applying the set operator is a table containing the following rows: i) Let R be a row that is a duplicate of some row in T1 or of some row in T2 or both. Let m be the number of duplicates of R in T1 and let n be the number of duplicates of R in T2, where m >= 0 and n >= 0. ii) If ALL is not specified, then Case: 1) If UNION is specified, then Case: A) If m > 0 or n > 0, then T contains exactly one dupli- cate of R. B) Otherwise, T contains no duplicate of R. regards, tom lane