title: Replace Union All to join to improve performance
body: <p>I have a working query which takes 20 mins to return data. I want to optimize it .
  I have table</p>
  
  <p>Incentives:</p>
  
  <pre><code>Transaction_ID | Incentive_On_A  | Incentive_On_B  | Incentive_On_C
  --------------+-----------------+-----------------+---------------
  1             | 0               | 0               | 10
  2             | 30              | 0               | 0
  3             | 0               | 20              | 0
  4             | 40              | 0               | 0
  </code></pre>
  
  <p>Required Output:</p>
  
  <pre><code>Transaction_ID| Product_Category | Incentive_Amt
   ----------   + -----------------+--------------
    1           | A                | 30
    2           | B                | 20
    3           | C                | 10
    4           | A                | 40
  </code></pre>
  
  <p>I am using this query :</p>
  
  <pre><code>   select Transaction_ID, 'A' as Product_Category,
         Incentive_On_A from Incentives
  Union all
     select Transaction_ID, 'B' as Product_Category,
         Incentive_On_B from Incentives
  Union all
     select Transaction_ID, 'C' as Product_Category,
         Incentive_On_C from Incentives
  </code></pre>
  
  <p>Is there any way I can optimize this query by removing union all with join?
  Thanks alot for the help.</p>
  
  <p>Edited**
  1.Added one more row in both the tables.
  Note:- Basically we are just doing a transpose of data - converting columns- 'Incentive_on_A','Incentive_on_B','Incentive_on_C' to a column - 'Category' having the values of the above 3 columns. </p>