SQL查询 - 具有内部联接的不同数据库

时间:2014-06-15 11:42:12

标签: mysql

我有两个DB-RATINGSAPP和MIGRATIONDATA。

我想在RATINGSAPP中使用MIGRATIONDATA中的表中的某些值更新表。我正在尝试运行此查询:

update r set internal_id = m.internal_id from ratingsapp.hotel03 as r 
    inner join migrationdata.migration as m on r.hotel_id = m.restaurant_id

这给了我错误:

   You have an error in your SQL syntax; 
    check the manual that corresponds to your MySQL server version for the right syntax to use near 
   'from ratingsapp.hotel03 as r inner join migrationdata.migration as m on r.hotel_' at line 1

但是类似的选择查询对我有效,并给出了正确的结果。

select r.hotel_id, m.internal_id from ratingsapp.hotel03 as r 
    inner join migrationdata.migration as m on r.hotel_id = m.restaurant_id

我在更新查询中做错了什么?

1 个答案:

答案 0 :(得分:0)

正确的MySQL语法是:

update ratingsapp.hotel03 r inner join
       migrationdata.migration as m
       on r.hotel_id = m.restaurant_id
   set internal_id = m.internal_id ;

MySQL更新中没有from子句。您正在使用SQL Server / Postgres语法。