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 |
GaryNull
Starting Member
14 Posts |
Posted - 2014-01-19 : 12:37:32
|
I want to get a list of any Categorieswhere ALL the products in that Category are not published (Published = 0).(I want to get the Categories where no products are listed for it)Here are the tables, not sure where to begin :SELECT [Id], PublishedFROM ProductWHERE Published = 0SELECT [Id] ,[Name]FROM CategorySELECT [Id] ,[ProductId] ,[CategoryId]FROM Product_Category_MappingThanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-19 : 12:44:09
|
[code]SELECT Id,NameFROM Categories cWHERE NOT EXISTS(SELECT 1FROM Product_Category_Mapping pcmINNER JOIN Product pON p.Id = pcm.ProductIdWHERE p.Published = 1AND pcm.CategoryId = c.Id)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
GaryNull
Starting Member
14 Posts |
Posted - 2014-01-19 : 13:20:21
|
Thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-20 : 06:24:56
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|