PostgreSql 与mysql 有很大的不同,表表更新就是一个例子
- 下面是PostgreSql 的通过A表更新B表
正确写法
update mesh set plan_id=p.id from plan p where mesh.project_id='201028085428118000' and mesh.project_id=p.project_id;
这里面有2张表,一张是mesh表,另一张是plan 表 切记需要更新的表(mesh)不能使用别名否则会报错,具体原因我也不清楚
- 再来一个mysql的表表更新
update mesh a,plan b set a.plan_id=b.plan_id where a.project_id=b.project_id and a.project_id='201028085428118000'
3.Sqlite中表表更新的写法
UPDATE table_a
SET
table_a.column_a_1 = (SELECT table_b.column_b_1
FROM table_b
WHERE table_b.user_name = table_a.user_name )
, table_a.column_a_2 = (SELECT table_b.column_b_2
FROM table_b
WHERE table_b.user_name = table_a.user_name )
WHERE
EXISTS (
SELECT *
FROM table_b
WHERE table_b.user_name = table_a.user_name
)