DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: SQL Query

  1. #1
    Join Date
    Nov 2002

    SQL Query

    We have a table which consist of following two fields

    Table name: Tab1
    Field1 Field3

    1 OK1

    1 OK2

    2 OK3

    2 OK4

    3 OK5

    For every Field1 value, We need to know the values of Field3 in a single row.

    Output has to be like this

    Field1 Field3(1) Field3(2)

    1 OK1 OK2

    2 OK3 OK4

    3 OK5 NULL

    Thanks In Advance


  2. #2
    Join Date
    Aug 2002
    Colorado Springs
    Your example suggests a maximum of two possible values of field3 for each field1, in which case,

    select field1,
    min_field3 field3_1,
    case when max_field3 !=min_field3 then max_field3
    else null
    end field3_2
    select field1,
    min(field3) min_field3,
    max(field3) max_field3
    from tab1
    group by field1

    The in-line view is not required, but it makes it a little clearer what is going on
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

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.