-1

I need to move data from column reg in table1 to reg2 in table2, where the ID of table1 = 'ID2' of table2.

basically, I need to shift car registrations from A to B as long as the person exists in B.

Shaun5
  • 57
  • 1
  • 8
  • 2
    Possible duplicate of [SQL update from one Table to another based on a ID match](https://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match) – Mukesh A Aug 13 '18 at 13:32
  • 1
    A `begin transaction`, an `insert into table2... select ...from table1 WHERE...` one `delete from table1 where ...` and a `commit` will do the work. When you provide more information on the table structure and example data may help to get an answer. – Myonara Aug 13 '18 at 13:36
  • 1
    Possible duplicate of [Move SQL data from one table to another](https://stackoverflow.com/questions/1612267/move-sql-data-from-one-table-to-another) – Feras Al Sous Aug 13 '18 at 13:45
  • You need sample data and desired results. I don't understand what you mean by "move". – Gordon Linoff Aug 13 '18 at 15:40
  • Thank you @Myonara – Shaun5 Oct 15 '18 at 08:27
  • @FerasAlSous thanks for point me in the right direction. – Shaun5 Oct 15 '18 at 08:28

2 Answers2

1

update table column by using join

update t2
set t2.reg2=t1.reg
from table2 t2 inner join table1 t1
on t2.ID2=t1.ID
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
0
INSERT INTO table2 (reg2)
SELECT reg
FROM table1
WHERE table2.ID2 = table1.ID;
Feras Al Sous
  • 1,073
  • 1
  • 12
  • 23