Monday, April 11, 2011

How can I rename a single column in a table at select?

I have two tables with one identical column name, but different data. I want to join the tables, but access both columns (row["price"], row["other_price"]): How can I rename/alias one of them in the select statement? (I do not want to rename them in the DB)

From stackoverflow
  • select table1.price, table2.price as other_price .....

  • us the AS keyword

    select a.Price as PriceOne, b.price as PriceTwo 
    from tablea a, tableb b
    
  • select t1.Column as Price, t2.Column as Other_Price
    from table1 as t1 INNER JOIN table2 as t2 
    ON t1.Key = t2.Key
    

    like this ?

  • if you are using sql server, use brackets or single quotes around alias name in a query you have in code.

0 comments:

Post a Comment