Re: Displaying two tables side by side

From: Michael Kleiser <mkl(at)webde-ag(dot)de>
To: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Displaying two tables side by side
Date: 2004-08-11 16:44:57
Message-ID: 411A4D09.2040500@webde-ag.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

select
( select a from t1 where CAST(t1.oid AS int) - CAST( (select min(oid) from t1) AS int ) = t_all.rownum ) AS a
, ( select b from t1 where CAST(t1.oid AS int) - CAST( (select min(oid) from t1) AS int ) = t_all.rownum ) AS a
, ( select c from t2 where CAST(t2.oid AS int) - CAST( (select min(oid) from t2) AS int ) = t_all.rownum ) AS a
, ( select d from t2 where CAST(t2.oid AS int) - CAST( (select min(oid) from t2) AS int ) = t_all.rownum ) AS a
from (
select cast(t1.oid AS int) - CAST( (select min(oid) from t1) AS int ) AS rownum
UNION
select cast(t2.oid AS int) - CAST( (select min(oid) from t2) AS int ) AS rownum
) AS t_all;

a | a | a | a
---+---+---+---
2 | 2 | 4 | 5
3 | 5 | 7 | 3
4 | 7 | 3 | 2
9 | 0 | 1 | 1
| | 2 | 0

David Garamond schrieb:
> 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.
>
> --
> dave
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michalis Kabrianis 2004-08-11 17:04:57 Re: Sum and count weird results
Previous Message Rosser Schwarz 2004-08-11 14:41:37 Re: function expression in FROM may not refer to other relations of same query level