Select query question

  • I have a question on a select query that will select a column name based on the result from another table...........

     

    table1

    united | delta | american

    500       7000      190        

     

    table2

    airline

    united 

    I'm trying to decide how to select the value of the record in the column in table1 that corresponds to the value in the record in table2.

     

    Thanks!

     

  • You need to "unpivot" table1, or bite the bullet and design the table in correct normalized form.

    This is an unpivot query.

    Select 'United' As Airline, united As SomeNumber

    Union All

    Select 'Delta' As Airline, delta As SomeNumber

    Union All

    Select 'American'As Airline, american As SomeNumber

    If you make this a view, you can join it to table2 on the [Airline] column

  • Thanks you're right I just wrote a query to put the table in the correct normalized form......

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply