From: Michael Glaesemann <grzm@myrealbox.com>
To: Michael Glaesemann <grzm@myrealbox.com>
Cc: Fay Du <fay.du@versaterm.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: How can I selet rows which have 2 columns values cross equal?
Date: Sat, 11 Mar 2006 18:35:04 +0900
Message-ID: <38FFEAFB-E746-408A-AB17-6A14FAABF731@myrealbox.com> (raw)
In-Reply-To: <B0FA7B5C-3766-478E-BDFD-CADC21B2AA0B@myrealbox.com>
References: <001d01c64445$fec23350$b8d849c6@versaterm.com>
<B0FA7B5C-3766-478E-BDFD-CADC21B2AA0B@myrealbox.com>
On Mar 11, 2006, at 16:46 , Michael Glaesemann wrote:
> select t1.id as t1_id, t2.id as t2_id
> from test t1
> join test t2 on (t1.a = t2.b and t1.b = t2.a)
> where t1.a < t2.a;
> t1_id | t2_id
> -------+-------
> 4 | 7
> 1 | 2
> (2 rows)
Just a follow-up (mostly to myself): I've been toying with using
natural joins recently, and here's the same query rewritten to use a
natural join:
select id as t1_id, t2_id
from test t1
natural join (
select id as t2_id
, a as b
, b as a
from test
) t2
where id < t2_id;
t1_id | t2_id
-------+-------
4 | 7
1 | 2
(2 rows)
Michael Glaesemann
grzm myrealbox com
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-sql@postgresql.org
Cc: grzm@myrealbox.com, fay.du@versaterm.com
Subject: Re: How can I selet rows which have 2 columns values cross equal?
In-Reply-To: <38FFEAFB-E746-408A-AB17-6A14FAABF731@myrealbox.com>
References: <001d01c64445$fec23350$b8d849c6@versaterm.com> <B0FA7B5C-3766-478E-BDFD-CADC21B2AA0B@myrealbox.com> <38FFEAFB-E746-408A-AB17-6A14FAABF731@myrealbox.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