Updating a table from a join

To understand this better let’s take a look at below contrived example. The opinions expressed here are my own and not of my employer.

updating a table from a join-1updating a table from a join-56updating a table from a join-70

So here it is: ' followed by the alias of the table (you don't need to say the table's name there) And (contrary to what some internet randos will tell you) you don't need to add a where clause to stop the update from applying to all rows of the table.SQL UPDATE JOIN means we will update one table using another table and join condition. I have updated customer table that contains latest customer details from another source system.I want to update the customer table with latest data.CREATE TABLE table1 (column1 INT, column2 INT, column3 VARCHAR (100)) INSERT INTO table1 (col1, col2, col3) SELECT 1, 11, 'FIRST' UNION ALL SELECT 11,12, 'SECOND' UNION ALL SELECT 21, 13, 'THIRD' UNION ALL SELECT 31, 14, 'FOURTH' CREATE TABLE table2 (column1 INT, column2 INT, column3 VARCHAR (100)) INSERT INTO table2 (col1, col2, col3) SELECT 1, 21, 'TWO-ONE' UNION ALL SELECT 11, 22, 'TWO-TWO' UNION ALL SELECT 21, 23, 'TWO-THREE' UNION ALL SELECT 31, 24, 'TWO-FOUR' Our requirement is that we have table 2 which has two rows where Col 1 is 21 and 31.We want to update the value from table 2 to table 1 for the rows where Col 1 is 21 and 31.

Leave a Reply