[MySQL] delete, update WITH where not exists

by ming
2014-12-06

# prepare create table test1(x int, y int); create table test2(x int, y int); # no problem delete a from test1 a where not exists (select 1 from test2 b where a.x = b.y); # problem (syntax error) delete a from test1 a where not exists (select 1 from test1 b where a.x = b.y); # solve delete a from test1 a left join test1 b on a.x = b.y where b.y is null # conclusion delete, update target_table ≠ where exists target_table