我有一个MySQL数据库,其中有两个表。一个表为“ url”,另一个表为“ stats”。
在“ URL”表中,“ id”列与在“ stats”表中的“ page_title”列具有完全相同的值。
我想做的是对照“ url.id”检查表“ stats.page_title”中的每个条目。如果在“ url.id”中找不到“ stats.page_title”中的值,则应删除“ stats.page_title”中的条目。
我怎么能这样?
与NOT EXISTS
:
delete from stats
where not exists (select 1 from url where url.id = stats.page_title)
或LEFT JOIN
:
delete s
from stats s
left join url u on u.id = s.page_title
where u.id is null
该条件where u.id is null
将仅删除不匹配的行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句