I have a database which holds a set of traders and a set of contracts. There is a field on the trader table which I need to update from a field on the contract table. Can anyone help with a sample query?
Asked
Active
Viewed 36 times
0
-
1What database are you using? Post the table schema. – Gurwinder Singh Feb 16 '17 at 20:04
-
@Rob The answers [here](http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server) should point you in the right direction. – Ethilium Feb 16 '17 at 20:17
-
Possible duplicate of [UPDATE from SELECT using SQL Server](http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server) – boxed__l Feb 16 '17 at 20:28
3 Answers
0
update trader
set trader.tofiled = contract.fromfield
from trader inner join contract on trader.id = contract.id
where put the condition

Sudesh Yadav
- 32
- 3
0
update trader join contract
on trader.id=contract.trader_id
set trader.field1=contract.field2

Mathew Thomas
- 84
- 7
0
Update trader
set t.tofield = c.fromfield
from trader t
join contract c on c.id = t.id
where t.id = 100
--make sure to select the row you want to update before you actually update to ensure you are updating the correct row.
select *
from trader t
join contract c on c.id = t.id
where t.id = 100

FarajDaoud
- 71
- 1
- 5