开发者

sql cross join query [closed]

开发者 https://www.devze.com 2023-01-11 14:04 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or开发者_运维技巧 rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or开发者_运维技巧 rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

I have more tables that I want to cross join them and I want to show each table with fields like this:

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

What should I do? How can i select fields with details like it's table's name.

thanks....


The easiest way is to use column aliasing, the same way you'd give it another name:

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]

I would recommend, however, that you use more decriptive names. Perhaps something like

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


Use aliases to give a meaningful description... for example

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号