From: Bruno Wolff III <bruno@wolff.to>
To: Mario Weilguni <mweilguni@sime.com>
Cc: jerome@gmanmi.tv
Cc: pgsql-general@postgresql.org
Subject: Re: SQL query...
Date: Wed, 19 Feb 2003 09:28:12 -0600
Message-ID: <20030219152812.GB17434@wolff.to> (raw)
In-Reply-To: <003b01c2d81c$3e716d20$8f01c00a@icomedias.com>
References: <200302200035.37249.jerome@gmanmi.tv>
<003b01c2d81c$3e716d20$8f01c00a@icomedias.com>
On Wed, Feb 19, 2003 at 14:38:53 +0100,
Mario Weilguni <mweilguni@sime.com> wrote:
> >if i have 5 tables and all of it has column X and i wanted to get unique
> >values in column X for all tables..
>
> >can i do it in one query?
>
> sure. this is one way to do this:
> select distinct foo.X from (
> select X from table1
> union
> select X from table2
> ....
> ) as foo;
>
> if the values are unique within every table, then you might want to omit the
> surrounding select.
Union's will already only return unique values. So you don't need the outer
select distinct. You might get better performance by using union alls
with select distinct, since only one sort will be needed. For the case
where you know they are all unique, you can use union alls without the
select distinct.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: bruno@wolff.to, mweilguni@sime.com, jerome@gmanmi.tv
Subject: Re: SQL query...
In-Reply-To: <20030219152812.GB17434@wolff.to>
References: <200302200035.37249.jerome@gmanmi.tv> <003b01c2d81c$3e716d20$8f01c00a@icomedias.com> <20030219152812.GB17434@wolff.to>
* 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