Solved

T-SQL UPDATE with JOIN

Posted on 2015-01-21
3
102 Views
Last Modified: 2015-01-21
I have two tables.  lets say a car table and a color table.   The color table has a single record per car and has a  FK to the car table.    I am moving the color directly into the car table.  I need to migrate existing data.  So, the new car table has a color column .

I'd like an UPDATE statement that does all records; that joins the two tables and updates the new color column in the car table based on the existing data in the color table.
0
Comment
Question by:HLRosenberger
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 40562847
update c
set Color = col.Color
from car as C
inner join Color as col
on col.carid = c.id
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40562884
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get Duration of last Status Update 4 34
Getting same value for every field in SQL 2 44
SQL Server 2012 r2 Make faster Temp Table 17 100
Sql Server group by 10 23
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now