[英]Sqlite Update query using a subquery
我要更新表test_test列"testconsent_id"
与值表的ID test_groupedconsent,
其中patient_id
在test_test
和patient_id
在test_groupedconsent
表匹配,也与两个表匹配CREATION_DATE。 我正在使用以下查询但收到错误 - "near "as": syntax error".
查询有什么问题?
Update test_test as Tinner join (select id,patient_id,creation_date from test_groupedconsent) as Aon A.patient_id = T.patient_id and A.creation_date = T.creation_dateset T.testconsent_id = A.id;
您不能直接在UPDATE语句中使用连接。
您必须使用相关子查询来查找所需的值(在子查询中,您可以执行任何操作,但在这种情况下,您甚至不需要连接):
UPDATE test_test
SET testconsent_id = (SELECT id
FROM test_groupedconsent
WHERE patient_id = test_test.patient_id
AND creation_date = test_test.creation_date);
听起来像是在加入表之后加入'as'所以要么把它放在(... as ...)中,要么在之前带上“ON COMMAND”! 像这样 - >(table1在table1.fiel = table2.field上连接table2)作为一些东西
UPDATE TABLE test_test
SET testconsent_id =
(SELECT testconsent_id FROM test_groupedconsent AS A, test_test AS B
WHERE A.patient_id = B.patient_id AND A.creation_date = B.A.creation_date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.