I have two tables profieltest
and parametertest
.
I want the value
column in profieltest
to be updated with the parameters from parametertest
where the user
id is the same and where the field_id = 2
in profieltest
. However if the combination between user
and field_id
in profieltest
doesn't exist i want it to be inserted from parametertest
. i tried it with an on duplicate key statement with an unique key: CREATE UNIQUE INDEX uniqfield ON profieltest (field_id, user)
, also profieltest.id
is an auto increment value. I tried the following query but it gives me an error :
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1(t1.user, t1.field_id, t1.value) VALUES( id ,t1.user = t2.user, t1.field_' at line 1
INSERT INTO profieltest t1(t1.user, t1.field_id, t1.value)
VALUES( id ,t1.user = t2.user, t1.field_id=2, t1.value=t2.parameter)
SELECT t2.user, t2.parameter
FROM parametertest t2
ON DUPLICATE KEY
UPDATE SET t1.value = t2.parameter
WHERE t1.User = t2.user
AND t1.Field_id = 2
edit: added the error.