I have a table that I just added a column to and now I am trying to find an easy way to update it.
select * from KioskGoals kg
inner join [TestDB].dbo.Kiosks k on kg.kioskID = k.Id
The joined table has the names I need. I want to update KioskGoals
table and set the kioskName
column = to the name returned from [TestDB].dbo.Kiosks
which would be k.name
Is this possible with a single query?
The table that needs to be updated is KioskGoals
. The column that needs to be updated is kioskName
.
Solution. Select column values in a specific order within rows to make rows with duplicate sets of values identical. Then you can use SELECT DISTINCT to remove duplicates. Alternatively, retrieve rows in such a way that near-duplicates are not even selected.
Unwanted rows in the result set may come from incomplete ON conditions. In some cases, you need to join tables by multiple columns. In these situations, if you use only one pair of columns, it results in duplicate rows.
The answer is yes, if there are any. If there are duplicate keys in the tables being joined.
UPDATE kg
SET Kg.kioskName = K.name
from KioskGoals kg inner join [TestDB].dbo.Kiosks k
on kg.kioskID = k.Id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With