Sql Inner Join Update Query

create table 1 and table 2

 

CREATE TABLE Table1
(
Id INT,
FruitName Varchar( 100)
);

CREATE TABLE Table2
(
Id INT,
FruitName Varchar( 100)
);

Insert into Table1 Values ( 1,’Mango’ ), ( 2, ‘Graps’), (3, ‘Banana’);
Insert into Table2 Values ( 1,’Mango’ ), ( 2, ‘vitthal’), (4, ‘Orange’);
SELECT * FROM Table1 ;
SELECT * FROM Table2 ;
SELECT *
FROM Table1 T1 Inner Join Table2 T2
ON T1. Id = T2 .Id;

update table2 set FruitName=null where id>1

UPDATE Table2
SET FruitName = t1.FruitName
FROM Table1 as t1 INNER JOIN Table2 T2
ON T1. Id = t2.Id;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s