X-Original-To: pgsql-general@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 525B947592C for ; Wed, 19 Feb 2003 09:31:58 -0500 (EST) Received: from biglumber.com (biglumber.com [207.228.252.42]) by postgresql.org (Postfix) with SMTP id 2EF3C4758C9 for ; Wed, 19 Feb 2003 09:31:57 -0500 (EST) Received: (qmail 1973 invoked from network); 19 Feb 2003 14:31:56 -0000 Received: from biglumber.com (HELO localhost) (207.228.252.42) by 0 with SMTP; 19 Feb 2003 14:31:56 -0000 From: greg@turnstep.com To: pgsql-general@postgresql.org Subject: Re: SQL query... X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 In-Reply-To: <003b01c2d81c$3e716d20$8f01c00a@icomedias.com> Date: Wed, 19 Feb 2003 14:31:56 -0000 X-Mailer: JoyMail 1.36 Message-ID: <37e29b3d0c58bc8199291d16782cc692@biglumber.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/1130 X-Sequence-Number: 37884 -----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-----