Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
durban
7 Posts |
Posted - 2006-07-14 : 09:05:34
|
| We have three tables: a master, a category and a relation table. A master can have many categories and a category can have may masters. These combinations are stored in the relation table. The question: I need to delete a category, which in turn means I need to delete all references to that category in the relation table. No problem so far. Now I need to delete only those master records whose only relation was with the deleted category while leaving those master records who are also related to other categories besides the deleted category. Can someone point me in the right direction.thanks dan |
|
|
humanpuck
Yak Posting Veteran
94 Posts |
Posted - 2006-07-14 : 09:25:00
|
| select * from master a left join category b on a.category_id = b.category_idwhere b.category_id is NULLand not exists(select c.master_id from master c inner join category d on c.category_id = d.category_id where a.master_id = c.master_id)That should get you a list of everything in the master tbl that has no association to the category tbl. |
 |
|
|
|
|
|