在表格中,我有以下模式
table1:
playerID int primary key,
nationalities nvarchar
table2:
playerID int,
pubVisited nvarchar
现在,我想将所有nationality为“England”的球员playedVisited设置为空,你有什么办法吗?
在表格中,我有以下模式
table1:
playerID int primary key,
nationalities nvarchar
table2:
playerID int,
pubVisited nvarchar
现在,我想将所有nationality为“England”的球员playedVisited设置为空,你有什么办法吗?
测试过SQL Server 2005。
update table2 set pubVisited = NULL
from
table1 t1
inner join
table2 t2
on (t1.playerID = t2.playerID and t1.nationalities = England )
根据nvarchar类型,您正在使用MSSQL。现在,在MySQL中,您可以在update .. where子句中使用子选择,但MSSQL有自己的update .. from子句:
UPDATE table2
SET
table2.pubVisited = null
FROM table1
WHERE
table2.playerID = table1.playerID and table1.nationalities = England
尚未进行测试,因此可能无法工作。
在Oracle中的语法将是:
update table2
set playedvisited = NULL
where playerID in (select playerID
from table1
where nationalities = England )