sql cross join查询

时间:2010-08-16 13:43:47

标签: sql database-table cross-join

我有更多的表格要加入它们,我希望每个表格显示如下字段:

  

tb1.filed1 tb1.filed2 tb2.filed1 .....

我该怎么办?如何选择包含表格名称等详细信息的字段。

感谢....

2 个答案:

答案 0 :(得分:4)

最简单的方法是使用列别名,就像给它另一个名字一样:

Select 
   tb1.filed1 as 'tb1.filed1', 
   tb1.filed2 as 'tb1.filed2', ... //continue for all your coumns
From table1 tb1
Inner Join table2 tb2 on [your criteria]
但是,我建议你使用更多的描述性名称。也许像是

Select 
  tb1.filed1 as 'RawInitialFiledDate', 
  tb1.filed2 as 'RawReFileDate',
  tb2.filed1 as 'ConfirmedInitialFiledDate', 
  tb2.filed2 as 'ConfirmedReFileDate'
from table1 tb1
Inner join table2 tb2...

答案 1 :(得分:1)

使用别名来提供有意义的描述......例如

select 
   tb1.field1 as "Order ID",
   tb1.field2 as "Order Date", 
   tb2.field1 as "Product ID"
   -- ,etc    
 from Orders tb1
 inner join OrderProducts tb2 on 
    tb2.OrderID = tb1.OrderID and
    tb1.OrderID = @OrderID