I have two databases and I want to update one table with values from another database table. I am using the following query but it does not work.
UPDATE database1.table1
SET field2 = database2.table1.field2
WHERE database1.table1.field1 = database2.table1.field1
I have also tried the following query but it does not work either:
UPDATE database1.table1
SET field2 = "SELECT field2 FROM database2.table1"
WHERE database1.table1.field1 = database2.table1.field1
Method 2: UPDATE from SELECT: The MERGE statementUse a MERGE statement for updating data in the [Employee] table. It then references another table when the USING clause is applied. The WHEN MATCHED then specifies the merge JOIN (Inner Join) between the source and target table.
Just add them together: UPDATE LOG SET TIME_EXIT = '2013/02/22' WHERE ID = ( SELECT ID FROM employee ORDER BY ID DESC LIMIT ); But based on that code currently it'll only ever update the last employee , you will need to select the correct employee by using some other identifier to ensure you have the correct one.
We can update the table using UPDATE statement in SQL. The update statement is always followed by the SET command. The SET command is used to specify which columns and values need to be updated in a table.
UPDATE 1
based on your comment, markup
should be part of the join. Here's the correct one:
UPDATE oman.ProductMaster_T
INNER JOIN main.ProductMaster_T
ON main.ProductMaster_T.ProductID = oman.ProductMaster_T.ProductID
SET oman.ProductMaster_T.Markup = main.ProductMaster_T.Markup
you can even add an ALIAS
to simplify the statement,
UPDATE oman.ProductMaster_T o
INNER JOIN main.ProductMaster_T m
ON m.ProductID = o.ProductID
SET o.Markup = m.Markup
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