Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > A sys func for ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3381 of 3559
Post > Topic >>

A sys func for a->b, b->c => a->c ?

by emilu@[EMAIL PROTECTED] (Emi Lu) Apr 2, 2008 at 10:21 AM

Good Morning,

Someone has better solution about the following query situation?

table test with two columns with primary key (id1, id2)
id1, id2
=========
1    2
1    3
12   3
13   5



Query conditions:
=====================
(1) a->b  => b->a
(2) a->b and a->c => a->c



Expected return:
id1   id2
===========
1     2
1     3
1    12

2    1
2    3
2    12

3    1
3    2
3    12

12   1
12   2
12   3

13   5


I did:

create view v_test AS
select id1 , id2 from test
union
select id2, id1  from test;


(
SELECT    a.id1 , b.id2
FROM      v_test AS a
left join v_test AS b
    ON (a.id2 = b.id1)
WHERE a.id1 <> b.id2
)
UNION
(
SELECT id1, id2
FROM   v_test
)
order by id1 ;


The query is a bit complex, do we have a better system func or query for 
this?

Thanks a lot!

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 1 Posts in Topic:
A sys func for a->b, b->c => a->c ?
emilu@[EMAIL PROTECTED]   2008-04-02 10:21:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 6 19:51:40 CDT 2008.