Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: A SQL Question
>Hi SQL Developers,
>
>I have a table as follows:
>
>Col1 Col2
>----------------
>A B
>C D
>E F
>G H
>B A
>E F
>C D
>H G
>
>With a PK on (Col1, Col2).
>
>How do I write a SQL script to get following
>result?
>
>Col1 Col2
>--------------------
>A B
>B A
>C D
>D C
>E F
>F E
>G H
>H G
>
>Thanks for your help.
>
>- Kirti
Kirti,
On your example 'ORDER BY COL1' should be enough :-). I have a solution which is not excellent (I dislike the way I prevent the query from returning too many rows), but seems to be working even when there is no transitivity. May at least give you an idea on which to start work :
select *
from (select *
from T connect by col1 = prior col2 and col1 > col2) x
Regards,
Stephane Faroult
Oriole
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Stephane Faroult INET: sfaroult_at_oriolecorp.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Mar 13 2003 - 08:34:49 CST
![]() |
![]() |