MYSQL 如果不存在则批量插入如果存在则更新
MYSQL Bulk insert if not exists update if exists
我正在寻找类似的东西-
insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = e, c = f;
注意 - 这里 table1.a 是唯一的密钥。
我遇到错误 - 未知列名称 'e'。
有什么解决方案可以将 'On duplicate key' 与 'Insert into Select' 语句一起使用吗?
谢谢!
使用别名造成的混乱
insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = table2.col2, c = table2.col3;
我正在寻找类似的东西-
insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = e, c = f;
注意 - 这里 table1.a 是唯一的密钥。
我遇到错误 - 未知列名称 'e'。
有什么解决方案可以将 'On duplicate key' 与 'Insert into Select' 语句一起使用吗?
谢谢!
使用别名造成的混乱
insert into table1(a, b, c)
select col1 as d, col2 as e, col3 as f from table2
on duplicate key update b = table2.col2, c = table2.col3;