Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

 I am having two tables in the SQL Server 2008 with the below structure:

Table1

- ID

- DescriptionID

- Description

Table2

- ID

- Description

Table1.DescriptionID maps to the Table2.ID. But, I don't want that any more. I need to be doing a bulk update to set the Description property of Table1 to the value associated with it in Table2. In other words, I need to be doing something like this:

UPDATE

  [Table1] 

SET

  [Description]=(SELECT [Description] FROM [Table2] t2 WHERE t2.[ID]=Table1.DescriptionID)

Can anyone guide me on how to do it. 

1 Answer

0 votes
by (12.7k points)

Your approach is right, and here is a different way you could do it:

update      Table1
set         Description = t2.Description
from        Table1 t1
inner join  Table2 t2
on          t1.DescriptionID = t2.ID

The nested select is a great way of just doing a join.

Want to be a SQL expert? Come and join this SQL Certification by Intellipaat.

For more information visit :

Related questions

0 votes
1 answer
asked Jul 16, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Dec 27, 2020 in SQL by Appu (6.1k points)

Browse Categories

...