From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
Cc: | "Fay Du" <fay(dot)du(at)versaterm(dot)com>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How can I selet rows which have 2 columns values cross equal? |
Date: | 2006-03-11 09:35:04 |
Message-ID: | 38FFEAFB-E746-408A-AB17-6A14FAABF731@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | AKHILESH GUPTA | 2006-03-11 10:29:20 | input from a external text file......! |
Previous Message | Michael Glaesemann | 2006-03-11 07:46:29 | Re: How can I selet rows which have 2 columns values cross equal? |