Sqlite Update query using a subquery
我必须用表
查询有什么问题?
1 | 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语句中直接使用联接。
您必须使用相关的子查询来查找所需的值(在子查询中,您可以随心所欲,但在本例中,您甚至不需要联接):
1 2 3 4 5 | 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",所以要么放入(…作为……)或在作为之前带上"命令"!像这样->(Table1将Table2连接到Table1.fiel=Table2.field上)作为
1 2 3 4 | 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) |