I have two MySQL tables, here’s how they are structured:
table foo(
foo_id varchar(32),
field1 varchar(32),
field2 varchar(32),
bar_id varchar(32)
);
table bar(
bar_id varchar(32),
field1 varchar(32),
field2 varchar(32)
);
I would like to update the foo table to have the same values for field1 and field2 as the bar table. I’ve tried the following two queries, both of which run without error, but don’t get me the results I want:
UPDATE foo LEFT JOIN bar ON foo.bar_id = bar.bar_id
SET foo.field1 = bar.field1 AND foo.field2 = bar.field2;
also
UPDATE foo,bar SET foo.field1 = bar.field1
AND foo.field2 = bar.field2 WHERE foo.bar_id = bar.bar_id
but neither work. what am I missing here?
I think maybe you have problems with
AND; should be comma instead. This way I think you are updatingfoo.field1to become(bar.field1 AND foo.field2 = bar.field2)(logical conjunction between non-zeroness ofbar.field1and equality offield2-s), and I’m pretty sure that’s not what you meant. Didn’t test though; might be wrong.