2017-07-06 109 views
0

我的更新查詢SQL Server作爲如下:SQL服務器相當於加入甲骨文更新

Update Project set Name=Project.Name+' assignedTo ' 
FROM Project 
INNER JOIN EmployeeProject ON Project.ID = EmployeeProject.ProjectID 
INNER JOIN Employee ON EmployeeProject.EmployeeID = Employee.ID 
WHERE (Employee.Name = N'Minion') 

的是等效的Oracle query.My嘗試如下:

Update (SELECT Project.Name as ProjectName,Employee.Name as EmpName 
     FROM Project 
     INNER JOIN EmployeeProject ON Project.ID = EmployeeProject.ProjectID 
     INNER JOIN Employee ON EmployeeProject.EmployeeID = Employee.ID 
     where Employee.Name=N'Minion' 
     ) T 
set T.ProjectName=' somting' 

但給我的錯誤不能修改列它映射到一個非鍵保存表。SQL Server服務器工作正常。

+0

@ a_horse_with_no_name可以爲您而發帖回答 – decoder

回答

1

你只需要exists

update Project p 
    set Name = p.Name+' assignedTo ' 
where exists (select 1 
       from EmployeeProject join 
        Employee e 
        on ep.EmployeeID = e.ID 
       where e.Name = N'Minion' and p.ID = ep.ProjectID 
      );