Sql 如何以其他方式左连接列
我想将右列映射到左列,但select语句出现错误,因为“select”附近的语法不正确。应为IDSql 如何以其他方式左连接列,sql,sql-server,Sql,Sql Server,我想将右列映射到左列,但select语句出现错误,因为“select”附近的语法不正确。应为ID create table [AdventureWorks2014].[abc] as select a.*, b.* from [Production].[Product] a left join( select distinct ProductID,Shelf from [Production].[ProductInventory] )b on a.ProductID = b. P
create table [AdventureWorks2014].[abc] as
select a.*,
b.*
from [Production].[Product] a
left join(
select distinct ProductID,Shelf
from [Production].[ProductInventory]
)b
on a.ProductID = b. ProductID;
尝试使用
选择进入:
select p.*, pi.shelf
into [AdventureWorks2014].[abc]
from [Production].[Product] p left join
(select distinct ProductID, Shelf
from [Production].[ProductInventory] pi
) pi
on p.ProductID = pi.ProductID;
注:
- 我不知道SQL Server支持将表创建为
- 表中的列需要有唯一的名称。如果使用
*
,您将获得ProductId
两次
- 表名的缩写是最好的命名约定;应避免使用无意义的字母,如
a
和b
尝试使用
选择进入:
select p.*, pi.shelf
into [AdventureWorks2014].[abc]
from [Production].[Product] p left join
(select distinct ProductID, Shelf
from [Production].[ProductInventory] pi
) pi
on p.ProductID = pi.ProductID;
注:
- 我不知道SQL Server支持将表创建为
- 表中的列需要有唯一的名称。如果使用
*
,您将获得ProductId
两次
- 表名的缩写是最好的命名约定;应避免使用无意义的字母,如
a
和b
您是否也在尝试创建表?您使用的是哪种DBMS?您是否也在尝试创建表?您使用的是哪种DBMS?