tags:

views:

43

answers:

2

Hi, given the first table ,i need to join this table with the same table and get the output table.Here we need to pair terms based on same seqid and the terms should be paired only from first table to second table.

Example:S1  T1  T2
        S1  T1  T3
        S1  T2  T3

this is the correct form of output but we should not get S1 T2 T1 and S1 T3 T2 once T1,T2 is already paired in the output table.

GIVEN TABLE:

   SEQID  TID                    

   S1      T1                 
   S1      T2                      
   S1      T3                      
   S2      T2                      
   S2      T3                       
   S2      T5                     
   S2      T6

OUTPUT:

 SEQID             TID       TID                
   S1              T1         T2
   S1              T1         T3               
   S1              T2         T3                
   S2              T2         T3               
   S2              T2         T5
   S2              T2         T6
   S2              T3         T5
   S2              T3         T6
   S2              T5         T6

Thanks in advance..

+3  A: 
SELECT  gt1.seqid, gt1.tid, gt2.tid
FROM    giventable gt1
JOIN    giventable gt2
ON      gt2.seqid = gt1.seqid
        AND gt2.tid > gt1.tid
Quassnoi
YAY it works !!! thanks a lot
Sree
@user: please mark the answer as accepted if it works as expected.
Quassnoi
A: 
Jeremy Wiggins