X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DC12D14B281C for ; Wed, 11 Aug 2004 14:38:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39019-08 for ; Wed, 11 Aug 2004 17:38:04 +0000 (GMT) Received: from camus.xss.co.at (camus.xss.co.at [194.152.162.19]) by svr1.postgresql.org (Postfix) with ESMTP id 6BCB914B27FF for ; Wed, 11 Aug 2004 14:38:00 -0300 (ADT) Received: from xss.co.at (ws1.intern.xss.co.at [192.168.162.51]) by camus.xss.co.at (8.12.10/8.12.10) with ESMTP id i7BHbwoJ012372; Wed, 11 Aug 2004 19:37:58 +0200 Message-ID: <411A5976.4090502@xss.co.at> Date: Wed, 11 Aug 2004 19:37:58 +0200 From: Andreas Haumer Organization: xS+S User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Garamond Cc: pgsql-sql@postgresql.org Subject: Re: Displaying two tables side by side References: <411A2926.9020500@zara.6.isreserved.com> In-Reply-To: <411A2926.9020500@zara.6.isreserved.com> X-Enigmail-Version: 0.74.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/87 X-Sequence-Number: 18584 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! David Garamond wrote: > How can you display two tables side by side? Example: > >> select * from t1; > a | b > ---+--- > 2 | 2 > 3 | 5 > 4 | 7 > 9 | 0 > >> select * from t2; > c | d > ---+--- > 4 | 5 > 7 | 3 > 3 | 2 > 1 | 1 > 2 | 0 > > Intended output: > a | b | c | d > ---+---+---+--- > 2 | 2 | 4 | 5 > 3 | 5 | 7 | 3 > 4 | 7 | 3 | 2 > 9 | 0 | 1 | 1 > | | 2 | 0 > > Each table has no keys (and no OIDs). Order is not important, but each > row from each table needs to be displayed exactly once. > You could try to use PosgreSQL's ctid system column to join on like this: test=# select *,ctid from t1; a | b | ctid - ---+---+------- 2 | 2 | (0,1) 3 | 5 | (0,2) 4 | 7 | (0,3) 9 | 0 | (0,4) test=# select *,ctid from t2; c | d | ctid - ---+---+------- 4 | 5 | (0,1) 7 | 3 | (0,2) 3 | 2 | (0,3) 1 | 1 | (0,4) 2 | 0 | (0,5) test=# select * from t1 right outer join t2 on (t1.ctid=t2.ctid); a | b | c | d - ---+---+---+--- 2 | 2 | 4 | 5 3 | 5 | 7 | 3 4 | 7 | 3 | 2 9 | 0 | 1 | 1 | | 2 | 0 Note that this is of course very platform specific. On Oracle you could use rownum, for example. I don't have a more portable solution on hand right now. HTH - - andreas - -- Andreas Haumer | mailto:andreas@xss.co.at *x Software + Systeme | http://www.xss.co.at/ Karmarschgasse 51/2/20 | Tel: +43-1-6060114-0 A-1100 Vienna, Austria | Fax: +43-1-6060114-71 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFBGll0xJmyeGcXPhERApQ5AKCrOdLg4i6UpycLUGWxTLIpe68C6QCgk2UP gcXbeO6VEw95obz1D8GQFQk= =Ksq6 -----END PGP SIGNATURE-----