2009-03-05 56 views
14

我有两个表有一个相同的列名称,但数据不同。我想加入表,但访问两列(行[“价格”],行[“other_price”]):如何在select语句中重命名/别名中的一个? (我不希望他们在DB重命名)如何在选择时重命名表格中的单个列?

回答

24

选择table1.price,table2.price作为other_price .....

+1

如何约25相同的列在两个表?我是否应该为所有25栏编写AS声明? – HPM 2013-05-18 03:45:14

5

我们AS关键字

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

像这个 ?

0

如果您正在使用sql server,请在代码查询中使用括号或单引号括住别名。

1

你也可以省略AS关键字。
SELECT row1 Price, row2 'Other Price' FROM exampleDB.table1;
在此选项中,可读性稍差,但您有期望的结果。

1

没有必要使用AS,只需使用:

SELECT table1.price Table1 Price, table2.price Table2 Price, ..... 
相关问题