mysql delete on join?

喜欢而已 提交于 2019-12-01 05:16:32

Disclaimer: I do not have access to a mysql database to test at the moment, but I think you can use:

delete s, r from send_txts s left join received_txts r on s.msg_link_id = r.id where r.action_id = 6;

See mysql's delete documentation for more information. A better method might be to put a foreign key constraint from received_txts to sent, and cascade the delete.

Personally I prefer the USING clause, but the previous answer is equally valid. I second the suggestion to look into using a foreign key constraint, it's a far more efficient way of accomplishing this.

DELETE FROM s, r USING sent_txts s LEFT JOIN received_txts r ON s.msg_link_id = r.id WHERE r.action_id = 6;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!