1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

SQL query

Discussion in 'SQL PL/SQL' started by krithika@2001, Jul 21, 2009.

  1. krithika@2001

    krithika@2001 Active Member

    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    80
    Hi

    I have a table1 which contains following columns

    decode_type FD1 FD2 FD3
    xxx abc def xyz

    table2

    decode_type Field

    XXX FD1


    Now i have to join these tables and get the FD1 value as 'abc' which is a row in another table.

    Can anybody help me with this solution

    Regards
    Krithika
     
  2. tyro

    tyro Forum Genius

    Messages:
    368
    Likes Received:
    20
    Trophy Points:
    260
    Location:
    India
    Hi

    could you explain a little more. What do you mean by
    ??
     
  3. rajavu

    rajavu Forum Guru

    Messages:
    815
    Likes Received:
    52
    Trophy Points:
    610
    Location:
    @ Bangalore , India
    You can do it by using the DECODE in single SQL in case if it has limitted fileds.

    Code (SQL):

    SQL> SELECT * FROM Test00;

    DECODE_TYP FIELD1
    ---------- ----------
    XXX        FD1
    YYY        FD2

    SQL> SELECT * FROM Test01;

    DECODE_TYP FD1        FD2        FD3
    ---------- ---------- ---------- ----------
    XXX        abc        def        xyz
    YYY        123        456        789

    SQL> SELECT T00.DECODE_TYPE, FIELD1,
      2         DECODE(FIELD1,'FD1',FD1,
      3                        'FD2',FD2,
      4                        'FD3',FD3) VALUE1
      5  FROM   TEST00 T00, TEST01 T01
      6  WHERE  T00.DECODE_TYPE = T01.DECODE_TYPE   ;

    DECODE_TYP FIELD1     VALUE1
    ---------- ---------- ----------
    XXX        FD1        abc
    YYY        FD2        456

    SQL>