Reputation: 28561
I have 2 tables with a few columns:
parent (id, name, a)
child (id, parent_id, name)
I cannot manage to find the proper SQL query to delete all parents that have no children and a<10. This is for SQLite shipped with Android 2.1. Anybody could help?
Upvotes: 1
Views: 173
Reputation: 356
Another way of doing it:
delete from parent
where a < 10
and id not in (select parent_id from child, parent b where child.parent_id = b.id)
Upvotes: 0
Reputation: 238226
delete from parent
where a < 10
and not exists (select * from child where parent.id = child.parent_id)
Upvotes: 3