Reputation: 1125
I need to update one column of table with other from same table
UPDATE table
SET table1.name = table1.nickname
FROM table
WHERE userid = 5
Is there any problem in my query, please help.
Upvotes: 2
Views: 114
Reputation: 493
Looks like you're adding some syntax you don't need...if all the data you need is already there in that table, simply do like so, regardless of which flavor of SQL (I think; I could be wrong on that part):
UPDATE dbo.tablename
SET columnToChange = columnWithCorrectValue
WHERE userid = 5
Upvotes: 3
Reputation: 6918
two things your are doing wrong:
your query should be:
UPDATE table
SET table.name = table.nickname
WHERE table.userid = 5
OR
UPDATE table
SET name = nickname
WHERE table.userid = 5
for more info regarding the syntax for update in sql server, please check this
Upvotes: 1