以下Oracle SQL是我怎样才能改变此Oracle SQL到MySQL
merge into table1 rs
using table2 ch
on (rs.id = ch.id)
when matched then
update set rs.column = ch.column
where rs.column is not null
我想改变这个SQL到MySQL。我怎样才能做到这一点?
以下Oracle SQL是我怎样才能改变此Oracle SQL到MySQL
merge into table1 rs
using table2 ch
on (rs.id = ch.id)
when matched then
update set rs.column = ch.column
where rs.column is not null
我想改变这个SQL到MySQL。我怎样才能做到这一点?
mySQL没有“MERGE”语句。 但是,有3种方法可以实现这一点:
1.使用@valicu2000的解决方案。
2.使用REPLACE语法
REPLACE into table1 rs(`column`) values(select column from table2 ch) where table1.id=table2.id and table2.column is not null
3.尝试事务更新和插入(但是,这会是2个查询)
即合并只是做一个更新,而不是插入。
所以,你可以使用update语句为它
update table1 rs
inner join table2 ch on rs.id = ch.id
set rs.column = ch.column
where rs.column is not null
如果你需要一个UPSERT,MySQL有一个insert on duplicate key update syntax
INSERT INTO table1的RS SELECT ch.column FROM表2 CH INNER JOIN表1 rs ON rs.id = ch.id其中rs.column不为null ON DUPLICATE KEY UPDATE rs.column = ch.column ...或与其非常接近的东西 – valicu2000
您是否尝试了解上述查询的作用并尝试将其转换? –
Google mysql合并。 –