sql cross join query [closed]
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
精彩评论