Comment puis-je traduire cette requête en SQLite:
UPDATE Table_1
INNER JOIN Table_2 ON (Table_1.Field1 = Table_2.Field1)
AND(Table_1.Field2 = Table_2.Field2)
SET Table_1.Field3 = Table_2.Field3
C'est ce que j'ai essayé.
UPDATE Table_1
SET Field3 = (SELECT Field3
FROM Table2
WHERE (Field1 = Table_2.Field1)
AND (Field2 = Table_2.Field2))
WHERE Field1 IN (SELECT Table_2.Field1
FROM Table2
WHERE (Field1 = Table_2.Field1)
AND (Field2 = Table_2.Field2))
AND Field2 IN (SELECT Table_2.Field2
FROM Table2
WHERE (Field1 = Table_2.Field1)
AND (Field2 = Table_2.Field2))
La requête fonctionne mais j'obtiens des résultats erronés.
Afin d'implémenter la jointure sur deux colonnes simultanément, vous pouvez utiliser un prédicat EXISTS:
UPDATE Table_1
SET Field3 = (SELECT Field3
FROM Table_2
WHERE (Table_1.Field1 = Table_2.Field1)
AND (Table_1.Field2 = Table_2.Field2))
WHERE EXISTS (SELECT *
FROM Table_2
WHERE (Table_1.Field1 = Table_2.Field1)
AND (Table_1.Field2 = Table_2.Field2));
Si vous utilisez version 3.15. ou ultérieure, vous pouvez également profiter de comparaisons de valeurs de ligne :
UPDATE Table_1
SET Field3 =
(SELECT Field3
FROM Table_2
WHERE (Table_1.Field1, Table_1.Field2) = (Table_2.Field1, Table_2.Field2))
WHERE (Field1, Field2) IN (SELECT Field1, Field2 FROM Table_2);