Sqlite update request using subquery

I need to update the test_test column with "testconsent_id"the id of the table test_groupedconsent,where the patient_idin test_testand patient_idin tables correspond test_groupedconsentand also create_date in both matches of the table. I am using the following query, but getting an error -"near "as": syntax error".

what is wrong with the request?

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;
+3
source share
3 answers

You cannot use a connection directly in an UPDATE statement.

You should use the correlated subquery to find the value you want (in the subquery you can do whatever you want, but in this case you don’t even need a connection):

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);
+3
source

, "" , (... ...), "ON COMMAND" ! → (table1 join table2 table1.fiel = table2.field) -

0
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)   
-1
source

All Articles