SQL query including and excluding result
Posted on 2014-03-04
I have a couple of tables that I want to query in my SQL Server database.
parentID, int (customerCategoryID of the parent to this row)
If a parentID is NULL then it is a parent and then of course those that have a parentID is a child to that parent.
I would like a query that:
Selects all customers in customerCategoryMember that are in a (or several) customerCategories and their childs.
but excludes those that are in another chosen category and its childs.
I want all members of customerCategories 5 and 10 with their respective childs (for 5 it is 6 and 7 and for 10 it's 11 and 12)
But I would like to exclude those members in the above query that is part of category 13 or 15, with their childs (14 and 16)
Is it possible for me to form such a query?
Thanks for help (and hopefully the question makes sense)!