PDA

View Full Version : SQL for deleting 'one' table records in one-to-many relationship


lanewalk
12-23-03, 04:06 AM
Hi,

Please help. I am trying work out how to delete all records in a table that do not have any foreign key values in the 'many' table. In other words, delete all customers who do not have orders or delete all books that do not have bookshops.

Many thanks,

Ed

hyjacked
12-23-03, 07:28 AM
delete from table_name where isnull(orders);

where orders is a valid column in table_name.

Note: you may have to change the where part of the clause depending on if your database supports isnull().