From: greg@turnstep.com
To: pgsql-general@postgresql.org
Subject: Re: SQL query...
Date: Wed, 19 Feb 2003 14:31:56 -0000
Message-ID: <37e29b3d0c58bc8199291d16782cc692@biglumber.com> (raw)
In-Reply-To: <003b01c2d81c$3e716d20$8f01c00a@icomedias.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> 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?
Yes, you want to use UNION:
SELECT foo FROM table1
UNION
SELECT foo FROM table2
UNION
SELECT foo FROM table3
UNION
SELECT foo FROM table4
UNION
SELECT foo FROM table5;
This will by default remove all duplicate entries. Use UNION ALL to
see all entries, even duplicated ones. Note that UNION (and its
companions INTERSECT and EXPECT) all require that the tables have
the same number of columns, and that each column is of a compatible
type.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200302190926
-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html
iD8DBQE+U5SSvJuQZxSWSsgRApdKAJ4oV4G1nq9RVoNbNX4qJ8hy/fI4eQCfTqcE
r3xW8sPVsIdwotPxoZHUHGk=
=P8cL
-----END PGP SIGNATURE-----
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: greg@turnstep.com
Subject: Re: SQL query...
In-Reply-To: <37e29b3d0c58bc8199291d16782cc692@biglumber.com>
References: <003b01c2d81c$3e716d20$8f01c00a@icomedias.com> <37e29b3d0c58bc8199291d16782cc692@biglumber.com>
* 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