DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005

    Question A tricky query needed

    I have two rows in my table myTable

    Row Name Flag1 Flag2 Number
    1 Primary Y N 1234
    2 Secondary N Y 4444

    I need a query which needs to fetch a single row like this

    Row Name Number
    1 Primary 4444

    The condition is like this
    The resultant record should pick the Name iff the Flag1 is Y and the Number iff the Flag2 is Y.

    Note: If I use 'Flag1 and Flag2' in my where clause I get don't get any records... If I use 'Flag1 or Flag2' I get two records but I want only one

  2. #2
    Join Date
    Dec 2000


    you can use pivot option

    1 select max(decode(rownum,1,col1,NULL)) col1
    2 ,max(decode(rownum,2,col1,NULL)) col2
    3 from (
    4 select rownum ,fl1
    5 ,case when fl1='Y' then col1 else to_char(val) end col1
    6 from foo1
    7* )
    SQL> /

    COL1 COL2
    ---------------------------------------- -------------------------
    primary 4444

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.