开发者

MySQL: Delete row if id doesn't exist in other table

开发者 https://www.devze.com 2023-03-23 14:26 出处:网络
I think this is newbie ask. How to delete row if id doesn\'t exist in other 开发者_如何学JAVAtable? My thought is fetch the ids first and delete. I\'m looking for better querying.You can set foreign k

I think this is newbie ask. How to delete row if id doesn't exist in other 开发者_如何学JAVAtable? My thought is fetch the ids first and delete. I'm looking for better querying.


You can set foreign keys to these tables.

More info here

for simple query, here it is:

 DELETE FROM table WHERE (SELECT count(1) FROM table2 WHERE id = table.id) < 1
0

精彩评论

暂无评论...
验证码 换一张
取 消