-2

Since I can't find any query here that works for me I've decided to ask a question.

I have table1 which has the next columns:

id | name | address | other_id
-------------------------------
1  | john | blvd 123| null

I have table2 which has the next columns:

id | other_id
--------------
1  | 20301

I would like to update table1.other_id with the table2.other_id according to the id.

What's the syntax for it ?

Thanks.

Alon
  • 3,734
  • 10
  • 45
  • 64

4 Answers4

0

try this:

UPDATE table1 JOIN table2  ON table1.id = table2.id set table1.other_id=table2.other_id
Jens
  • 67,715
  • 15
  • 98
  • 113
0
UPDATE table1 JOIN table2 
ON tabel1.id = table2.id
SET table1.other_id=table2.other_id;
SEB BINFIELD
  • 410
  • 3
  • 12
0

Use this query

UPDATE table1 u
INNER JOIN table2 s on
    u.other_id= s.other_id
SET u.other_id= s.other_id
Farshad
  • 1,465
  • 1
  • 9
  • 12
0

Firstly, table1 should point table1.other_id as foreign key mapped to table2.other_id. For insert you can use the following statement:

INSERT INTO table1(other_id) SELECT table2.other_id FROM table2 WHERE table2.other_id=1;  
aime
  • 117
  • 1
  • 3
  • 12