pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Domoszlai László <dlacko@finit.hu>
Cc: SQL PostgreSQL (E-mail) <pgsql-sql@postgresql.org>
Subject: Re: set difference
Date: Tue, 15 Oct 2002 10:25:39 -0400
Message-ID: <14808.1034691939@sss.pgh.pa.us> (raw)
In-Reply-To: <D6CD29CE4DF67F47A11FB6CF5EBE15D10ECC55@gedeon.finit.local>
References: <D6CD29CE4DF67F47A11FB6CF5EBE15D10ECC55@gedeon.finit.local>

=?iso-8859-1?Q?Domoszlai_L=E1szl=F3?= <dlacko@finit.hu> writes:
> I would like to make symmetrical(set) difference in a query.
> But the simpliest way I could find is 

> select id from a 
> except
> select id from b
> union 
> select id from b
> except
> select id from a

> Is there any better solution for this problem?

One thing you should definitely do is change "union" to "union all".
"union" implies a pass of duplicate removal, which shouldn't be
necessary here (unless a or b individually contain duplicates and
you want to get rid of those too).

Another thing to try is
	(a union b) except (a intersect b)
(Again, you might be able to say union all instead of union.)
Not sure which will be faster.

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <14808.1034691939@sss.pgh.pa.us>
Permalink:  ../14808.1034691939@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14808.1034691939@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dlacko@finit.hu
  Subject: Re: set difference
  In-Reply-To: <14808.1034691939@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox