Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用子查询的Sqlite更新查询_Sql_Sqlite - Fatal编程技术网

使用子查询的Sqlite更新查询

使用子查询的Sqlite更新查询,sql,sqlite,Sql,Sqlite,我必须用table test_groupedapprove的id值更新table test_test列testapprove_id,其中test_test中的患者id与test_groupedapprove表中的患者id匹配,并且 另外,两个表中的创建日期都匹配。 我正在使用下面的查询,但得到的错误-近似为:syntax error 这个查询有什么问题 Update test_test as Tinner join (select id,patient_id,creation_date from

我必须用table test_groupedapprove的id值更新table test_test列testapprove_id,其中test_test中的患者id与test_groupedapprove表中的患者id匹配,并且 另外,两个表中的创建日期都匹配。 我正在使用下面的查询,但得到的错误-近似为: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放在。。。像或者在你之前发出命令!
像这样->table1将table1.fiel=table2.field作为某物加入table1.fiel=table2.field,我尝试了查询,但这使所有条目的testapprovement\u id=1。我运行了UPDATE moz\u bookmarks SET dateAdded=SELECT dateAdded FROM places\u backup.moz\u bookmarks,其中guid=moz\u bookmarks.guid;它将所有行的dateAdded值重置为相同。这在更新中缺少where子句,下面的答案也是如此。
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);