Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MrCapuchino
Starting Member
9 Posts |
Posted - 2010-07-16 : 23:46:57
|
| Hello,I have 2 tablesTable 1name | lastnamejim johnsonjohn johnsontable 2id | user | othername1 johny johnson2 johny stewartI want to copy the values from table1.lastname into table2.othernameI tried thisUPDATE table2 set othername = (select lastname from table1) where name = 'john'I get an error saying it cannot copy more than one value.Any ideas?Thanks |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-07-17 : 00:45:17
|
I think this is what you're trying to doUPDATE t2SET othername = t1.lastnameFROM Table1 t1JOIN Table2 t2ON t2.user = t1.nameWHERE t1.name = 'john' but you're going to trash table 2 if there is more than one 'john' in table 1 |
 |
|
|
MrCapuchino
Starting Member
9 Posts |
Posted - 2010-07-17 : 09:06:50
|
| Hello, Could you help me understand the query?I mean t2.user = t1.name if you look closely there is no equal value in those 2 columns.But let me give you a more clear example of my table.TABLE1Categories | DivisionCAT1CAT2CAT3CAT4CAT5Username | Categories2JOHNJOHNJOHNJOHNJOHNso Basically, I wanto to copy the categorios column from TABLE1 to the Objectives column in TABLE2 where the username is 'JOHN' resulting inTABLE2Username | Categories2JOHN CAT1JOHN CAT2JOHN CAT3JOHN CAT4JOHN CAT5THANKS |
 |
|
|
|
|
|