I have two tables with a many-to-one relation. I can select items in the "child" table with a criteria in the parent table using an implicit join:
select * from child,parent where child.parentid=parent.id and parent.name like 'foobar%'
Is there a better (more efficient, more elegant) way to delete children that a plain:
delete from child where child.parentid in (select id from parent where parent.name like 'foobar%')
This answer hints that I could do:
delete child from child,parent where child.parentid=parent.id and parent.name like 'foobar%'
But on PostgreSql (through SquirrelSQL) I get a syntax error... of course I have long table names so the actual request is more like:
delete c from child c, parent p where c.parentid=p.id and p.name like 'foobar%'
So is this supported by PG, or is there another way?
Bonus points: can I delete items from the two tables using:
delete from child,parent where child.parentid in (select id from parent where parent.name like 'foobar%')