I used to be an oracle wiz but am very rusty after 8 years of project managing, my developer is on leave and the fix he put in place doesn't work, so am trying to fix it myself: This sql runs but the result is all rows are updated and the comment_text is now blank.

When you sign in to comment, IBM will provide your email, first name and last name to DISQUS.

If it does, then only one of the join rows will be used to update the target row, but which one will be used is not readily predictable.

sql updating table from same table-62

Putting it all together In this example I will take a Products table as target table and Updated Products as a source table containing updated list of products.

I will then use the MERGE SQL command to synchronize the target table with the source table.

In this tip we will walk through how to use the MERGE statement and do this in one pass.

Beginning with SQL Server 2008, now you can use MERGE SQL command to perform these operations in a single statement.

The MERGE statement basically merges data from a source result set to a target table based on a condition that you specify and if the data from the source already exists in the target or not. We can see the Coffee rate was updated from 20.00 to 25.00, the Muffin rate was updated from 30.00 to 35.00, Biscuit was deleted and Pizza was inserted.

The new SQL command combines the sequence of conditional INSERT, UPDATE and DELETE commands in a single atomic statement, depending on the existence of a record.

That information, along with your comments, will be governed by DISQUS’ privacy policy.

By commenting, you are accepting the IBM commenting guidelines and the DISQUS terms of service.

The new MERGE SQL command looks like as below: The MERGE statement basically works as separate insert, update, and delete statements all within the same statement.

You specify a "Source" record set and a "Target" table, and the join between the two. Rate) --When there is a row that exists in target table and --same record does not exist in source table --then delete this record from target table WHEN NOT MATCHED BY SOURCE THEN DELETE --$action specifies a column of type nvarchar(10) --in the OUTPUT clause that returns one of three --values for each row: 'INSERT', 'UPDATE', or 'DELETE', --according to the action that was performed on that row OUTPUT $action, DELETED.

You would need to write separate INSERT, UPDATE and DELETE statements to refresh the target table with an updated product list or do lookups.