• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 112
  • Last Modified:

T-SQL UPDATE with JOIN

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
HLRosenberger
Asked:
HLRosenberger
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
update c
set Color = col.Color
from car as C
inner join Color as col
on col.carid = c.id
0
 
HLRosenbergerAuthor Commented:
Thanks!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now