forum.venkateswarlu.net
      Register      Login
Update with Inner Join in SQL Server

2 replies to this topic

Jahnavi N #1
Member
164 Points
Posted on 19 Feb 2013 05:02 PM IST Hi,

I want to update one table column with another table column by using inner join.

Is this possible, If yes please share the sql query.

Thanks
Jahnavi
 
SQL Server     834 views     Reply to this topic
Ravikumar S #2
Member
12 Points
Replied on 23 May 2013 05:27 PM IST

Hi Jahnavi,


 


try this way..


Update  a


set a.Column1=b.column1


from <Table> a


inner join <Table> b


on a.column=b.column


where <condition>


 


eg: update a


set a.deptid=b.deptid


from emp a


inner join dept b


on a.deptno=b.deptno


where a.empname='john'


 


please correct me ,if i'm wrong.

 
Reply to this topic
Jahnavi N #3
Member
164 Points
Replied on 01 Jun 2013 11:36 AM IST Hi Ravikumr,

Thanks for your reply. The query you shared is working fine and I got some idea on how to use JOINS to update the tables.

Please keep on sharing the SQL quires for interview purpose.
I have faced this question in an interview, until I don't there is a possibility to update tables using joins.

Thanks,
Jahnavi.
 
Reply to this topic