2017-03-06 32 views
0

結合縱列我要地圖右欄離開,但我得到的錯誤在SELECT語句附近有語法錯誤select'.Expecting 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. ProductID; 
+1

你也試圖創建一個表? – VDK

+0

你正在使用哪些DBMS? –

回答

4

嘗試使用SELECT INTO

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支持CREATE TABLE AS
  • 表中的列需要具有唯一的名稱。如果您使用*,您將獲得兩次ProductId
  • 表名縮寫是最好的命名約定;應避免使用無意義的字母,例如ab