Hello SQL experts,
It's me the SQL newbie again. This time I'm trying to update a table with data from another table. Seems like a simple thing, but I can't seem to get it right. Here's some background info:
<TARGET Table>
ID,Title,Firstname,Lastname,Nationality,Religion,Sex
<SOURCE table>
ID,Nationality,Religion,Sex
The TARGET table already have ID and names populated, I'm just trying to add Nationality, Religion, Sex to it. Here's what I'm trying to execute:
UPDATE target
SET Nationality=(SELECT Nationality FROM SOURCE where TARGET.[ID]=SOURCE.[ID])
But I keep getting this error:
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =,!=,<,<=,>,>= or when the subquery is used as an expression.
This statement has been terminated.
The SOURCE table has less data than the TARGET, and also has some duplicate data within SOURCE dable. Could this be the issue?
Any thoughts or suggestion?
Thank you very much in advance,
dragony
It's me the SQL newbie again. This time I'm trying to update a table with data from another table. Seems like a simple thing, but I can't seem to get it right. Here's some background info:
<TARGET Table>
ID,Title,Firstname,Lastname,Nationality,Religion,Sex
<SOURCE table>
ID,Nationality,Religion,Sex
The TARGET table already have ID and names populated, I'm just trying to add Nationality, Religion, Sex to it. Here's what I'm trying to execute:
UPDATE target
SET Nationality=(SELECT Nationality FROM SOURCE where TARGET.[ID]=SOURCE.[ID])
But I keep getting this error:
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =,!=,<,<=,>,>= or when the subquery is used as an expression.
This statement has been terminated.
The SOURCE table has less data than the TARGET, and also has some duplicate data within SOURCE dable. Could this be the issue?
Any thoughts or suggestion?
Thank you very much in advance,
dragony