我有2个表,列有几列:
parent (id, name, a)
child (id, parent_id, name)
我无法找到正确的SQL查询来删除所有没有子级且< 10的父级。这适用于Android 2.1附带的SQLite。有人可以帮忙吗?
答案 0 :(得分:3)
delete from parent
where a < 10
and not exists (select * from child where parent.id = child.parent_id)
答案 1 :(得分:0)
另一种方法:
delete from parent
where a < 10
and id not in (select parent_id from child, parent b where child.parent_id = b.id)