I have looked at SQL update query using joins ..but it is not exactly what I need (I am used to cook-book SQL, and can't figure out how to modify the answers).
I have a table "a" and a table "b". I want to update field f1 in "a" if and only if "b" has a record with fields f1, f2, f3 equal to f1, f2, f3 in table "a".
So, if I have
TABLE a
f1 f2 f3 ...
------------------------------------------
m a1a 1a1 1-1-1980
m a1a 1a1 1-1-1980
m b1b 1b1 18-1-1982
m c1c 1c1 16-4-1975
TABLE b
f1 f2 f3 ...
------------------------------------------
m b1b 1b1 18-1-1982
m c1c 1c1 16-4-1975
Do update. Then Table "a" looks like:
TABLE a
f1 f2 f3 ...
------------------------------------------
m a1a 1a1 1-1-1980
m a1a 1a1 1-1-1980
m b1b 1b1 *-1-1982
m c1c 1c1 *-4-1975
I know how to do the string manipulation... but the update query is not something I'm used to, especially in this context. I would appreciate your help.
Thank you!
EDIT: I am using sqlite
EDIT 2: Here is a query that user suggested, but it is not working currently to update records (probably my mistake):
UPDATE diseases
SET dateofbirth='*'||ltrim(dateofbirth,0123456789)
WHERE gender=(SELECT a1.gender FROM diseases AS a1
INNER JOIN stage2helper AS b ON a1.gender = b.gender AND
a1.dateofbirth = b.dateofbirth AND a1.postalcode = b.postalcode)
AND postalcode=(SELECT a1.postalcode FROM diseases AS a1 INNER JOIN stage2helper AS b ON a1.gender = b.gender AND a1.dateofbirth = b.dateofbirth AND a1.postalcode = b.postalcode)
AND dateofbirth=(SELECT a1.dateofbirth FROM diseases AS a1 INNER JOIN stage2helper AS b ON a1.gender = b.gender AND a1.dateofbirth = b.dateofbirth AND a1.postalcode = b.postalcode);