且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用其他表中的外键删除主键的行?

更新时间:2023-01-29 16:19:07

You can delete from multiple tables in one query:

DELETE agenda.*, agendadatum.*
FROM agenda
JOIN agendadatum USING (idagenda)
WHERE tot < NOW();

This will delete rows from both agenda and agendadatum, and only those rows matching the conditions (same rows as returned by the query if you replaced DELETE with SELECT).