使用多个JOIN执行MySQL UPDATE

时间:2014-12-10 20:05:17

标签: mysql

我有以下有效的查询...

SELECT u.route_id, g.route_id
FROM user_route u
JOIN user_address a ON a.address_id = u.route_begin_id
JOIN user_address b ON b.address_id = u.route_finish_id
JOIN google_route g ON g.route_begin_id = a.address_google_id 
AND g.route_finish_id = b.address_google_id

但我想用g.route_id的值更新u.google_route_id

任何人都可以建议我如何解决这个问题,谢谢。

1 个答案:

答案 0 :(得分:0)

update user_route u
JOIN user_address a ON a.address_id = u.route_begin_id
JOIN user_address b ON b.address_id = u.route_finish_id
JOIN google_route g ON g.route_begin_id = a.address_google_id 
AND g.route_finish_id = b.address_google_id)
set u.google_route_id=g.route_id