删除另一个表中没有关联行的行

时间:2011-02-01 18:04:14

标签: android sql sqlite

我有2个表,列有几列:

parent (id, name, a) 
child (id, parent_id, name)

我无法找到正确的SQL查询来删除所有没有子级且< 10的父级。这适用于Android 2.1附带的SQLite。有人可以帮忙吗?

2 个答案:

答案 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)
相关问题