简体   繁体   English

从SQL Server中的2个表中获取不同的列名称

[英]getting different column names from 2 tables in sql server

I have Item and Sales tables with different columns like, 我的Item和Sales表具有不同的列,例如,

Item 项目

ItemName                        
Itemcost                       
ItemQty                         

Sales 营业额

 SalesName     
 SalesDate  
 SalesQty

In the above tables there is not common column,but i need to get output as 在上面的表中没有通用列,但是我需要获取输出

ItemName,ItemCost,SalesName,SalesDate.

I tried with union, 我尝试过工会

select ItemName,ItemCost from Item
union     
select SalesName,SalesDate from Sales

but am getting only 1 table columns like ItemName,ItemCost 但只得到1个表列,例如ItemName,ItemCost

Please help me on this issue 请帮我解决这个问题

Thanks In Advance 提前致谢

Venkat. 文卡特

Use below sql query : 在下面的sql查询中使用:

select i.ItemName, i.ItemCost, s.SalesName, s.SalesDate 
from Item as i, Sales as s;

Use the below query : 使用以下查询:

This will join every row in table1 with table2 (the Cartesian product) returning all columns. 这会将table1中的每一行与table2(笛卡尔积)连接起来,并返回所有列。

Select im.ItemName, im.ItemCost, sl.SalesName,sl.SalesDate from Item as im, Sales as sl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM