I can do the following to insert records into a table from a select on another table:
INSERT INTO table (field1, field2) SELECT field1,field2 FROM table2
Can I do the same with an update ?? Something like this (not working!):
UPDATE table SET field1=table2.field1, field2=table2.field2 SELECT field1,field2 FROM table2
WHERE table.field0=table2.field0
I know how to do this with only 1 field, but is there a way to do it with multiple fields?
We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.
To update multiple columns use the SET clause to specify additional columns. Just like with the single columns you specify a column and its new value, then another set of column and values. In this case each column is separated with a column.
The UPDATE statement in SQL is used to update the data of an existing table in database. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. UPDATE table_name SET column1 = value1, column2 = value2,...
UPDATE table A INNER JOIN table2 B USING (field0)
SET A.field1 = B.field1,A.field2 = B.field2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With