Pistolo
Pistolo

Reputation: 133

Update table with another table values

There are two MySQL tables, the update is working in local test mode against H2, also the query is fine with the MySQL command line. But it fails when Play tries to use the query in an evolution file.

Play: 2.5.6 Scala: 2.11.8

Query:

UPDATE table1 t1,table2 t2     
SET t1.user_id = t2.id
WHERE t1.buyer_id = t2.buyer_id;

Error:

[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[error] p.a.d.e.DefaultEvolutionsApi - Syntax error in SQL statement "UPDATE table1 t1,[*]table2 t2
SET t1.user_id = t2.id
WHERE t1.buyer_id = t2.buyer_id;"; expected "SET"; SQL statement:
UPDATE table1 t1,table2 t2     
SET t1.user_id = t2.id
WHERE t1.buyer_id = t2.buyer_id[42001-191] [ERROR:42001, SQLSTATE:42001]

Upvotes: 0

Views: 99

Answers (2)

anil_g
anil_g

Reputation: 54

update table1 join table 2 on table1.id = table2.id
set table1.name = table2.customername,
    table1.mobilenum = table2.phonenum ; 

Upvotes: 1

Ullas
Ullas

Reputation: 11556

Query

UPDATE table1 t1
JOIN table2 t2
ON t1.buyer_id = t2.buyer_id 
SET t1.user_id = t2.id;

Upvotes: 0

Related Questions