SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 UPDATE table A with values FROM table B
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

beemd
Starting Member

14 Posts

Posted - 10/28/2013 :  16:19:53  Show Profile  Reply with Quote
Hi,

If I have two tables like this (simplified example)

dbo.a
id value
1 A
2 B
3 C

dbo.b
id value
1
2
3

I want to update b and set the value from a where the id's match? Could someone point me in the right direction?

Thanks

James K
Flowing Fount of Yak Knowledge

3575 Posts

Posted - 10/28/2013 :  16:48:51  Show Profile  Reply with Quote
You can do it like shown below:
UPDATE b SET 
	value = a.VALUE
FROM
	a INNER JOIN b ON a.id = b.id;
The only thing to be careful about is that if there is more than one row in table a for a given id in table b, it is unpredictable which of those rows in table a will be used to pick the value from to be used to update b
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000