我需要更新SQLite表。
表格如下:
ID | Address | CallNumber | RefID
-----+--------------------+-------------------------------------------
ef78 | library | 2002/13 | 100002
no56 | Lit | 0189 | 100003
rs90 | temp | | 100003
对于Address =“Lit”的每一列,都有一个具有相同RefID的列Address ='temp'。 现在我需要使用具有相同RefID的列中的值“CallNumber”更新每个Address =“temp”。
更新的表应如下所示:
ID | Address | CallNumber | RefID
-----+--------------------+-------------------------------------------
ef78 | library | 2002/13 | 100002
no56 | Lit | 0189 | 100003
rs90 | 0189 | | 100003
我试过了:
UPDATE Location
SET address = foo.callnumber
FROM (select RefID, CallNumber FROM Location) foo
WHERE foo.RefID=Location.RefID AND Location.Address = 'temp';
但我得到的是“from”附近的语法错误。
有任何线索吗?
答案 0 :(得分:12)
UPDATE
命令do not have a FROM
clause。
使用相关子查询:
UPDATE Location
SET Address = (SELECT CallNumber
FROM Location L2
WHERE L2.RefID = Location.RefID
AND L2.Address = 'Lit')
WHERE Address = 'temp'