| Author | Topic | 
                            
                                    | magmoAged Yak Warrior
 
 
                                        558 Posts | 
                                            
                                            |  Posted - 2013-07-29 : 06:31:32 
 |  
                                            | HiI have the following Query.... SELECT DISTINCT TOP (100) PERCENT dbo.tbl_Products.Text, dbo.tbl_Products.NodeId, dbo.tbl_Products.ParentNodeIdFROM            dbo.tbl_DivisionAssociation INNER JOIN                         dbo.tbl_NodeDivisionAssosiation ON dbo.tbl_DivisionAssociation.DivisionID = dbo.tbl_NodeDivisionAssosiation.DivisionID INNER JOIN                         dbo.tbl_Products ON dbo.tbl_NodeDivisionAssosiation.NodeID = dbo.tbl_Products.NodeIdWHERE        (dbo.tbl_DivisionAssociation.UserID = 1)What this does is to show all the rows in tbl_Products based on weather user is associated with a DivisionID and that DivisionID have the NodeID in tbl_NodeDivisionAssociation. I would like to show the NodeID's that are not associated in the tbl_NodeDivisionAssociation table.The tbl_Products table is built as a tree structure, what this means is that a NodeID can have ParentNodeID value, if so it means that the Product is placed in that folder. For example like this....NodeID    ParentNodeID    Text           NavigateUrl1                         Books          #2         1               Inferno        page.html3                         Manuals        #4         3               Sony           #5         3               Panasonic      #6         4               Sony X Model   page.htmlIf possible I only like to retrieve the rows that have a ParentNodeID and also something else than # in the NavigateUrl field. In the case above the rows that should be displayed are...InfernoSony X model |  | 
       
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-29 : 06:59:19 
 |  
                                          | [code]SELECT DISTINCT TOP (100) PERCENT p.Text, p.NodeId, p.ParentNodeIdFROM            dbo.tbl_Products pLEFT JOIN       dbo.tbl_NodeDivisionAssosiation ndaON nda.NodeID = p.NodeIdLEFT JOIN       dbo.tbl_DivisionAssociation daON da.DivisionID = nda.DivisionIDAND da.UserID = 1WHERE p.ParentNodeID IS NOT NULLAND p.NavigateUrl <> '#'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | magmoAged Yak Warrior
 
 
                                    558 Posts | 
                                        
                                          |  Posted - 2013-07-29 : 07:25:24 
 |  
                                          | HiThis Query give me all rows from tbl_Products, I would like to receive only the ones that doesn't have a nodeid value in the tbl_NodeDivisionAssosiation table. |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-29 : 07:29:21 
 |  
                                          | [code]SELECT TOP (100) PERCENT p.Text, p.NodeId, p.ParentNodeIdFROM            dbo.tbl_Products pWHERE p.ParentNodeID IS NOT NULLAND p.NavigateUrl <> '#'AND NOT EXISTS(SELECT 1FROM        dbo.tbl_NodeDivisionAssosiation ndaWHERE nda.NodeID = p.NodeId)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | magmoAged Yak Warrior
 
 
                                    558 Posts | 
                                        
                                          |  Posted - 2013-07-29 : 07:41:33 
 |  
                                          | Almost there, there is a relationship between tbl_DivisionAssociation and dbo.tbl_NodeDivisionAssosiation on DivisionID. The User (UserID in tbl_DivisionAssociation) can be part of several DivisionID so there must also be a join based on that. Also, is it possible to add the "folder" name as I mentioned? |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-30 : 02:42:54 
 |  
                                          | quote:But your explanation just saidI would like to receive only the ones that doesn't have a nodeid value in the tbl_NodeDivisionAssosiation tableso do you really need to care about DivisionID here?for getting foldername you need to add a self joinOriginally posted by magmo
 Almost there, there is a relationship between tbl_DivisionAssociation and dbo.tbl_NodeDivisionAssosiation on DivisionID. The User (UserID in tbl_DivisionAssociation) can be part of several DivisionID so there must also be a join based on that. Also, is it possible to add the "folder" name as I mentioned?
 
 SELECT TOP (100) PERCENT p.Text, p.NodeId, p.ParentNodeId,p1.Name AS FolderNameFROM            dbo.tbl_Products pINNER JOIN dbo.tbl_Products p1ON p1.NodeID = p.ParentNodeID WHERE  p.NavigateUrl <> '#'AND NOT EXISTS(SELECT 1FROM        dbo.tbl_NodeDivisionAssosiation ndaWHERE nda.NodeID = p.NodeId)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | magmoAged Yak Warrior
 
 
                                    558 Posts | 
                                        
                                          |  Posted - 2013-07-30 : 03:03:57 
 |  
                                          | Sorry for that, but if a user do beling To a division I need To consider that, otherwise it wont be correct |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-30 : 03:40:54 
 |  
                                          | That was not clear from your explanation at all!anyways try SELECT TOP (100) PERCENT p.Text, p.NodeId, p.ParentNodeId,p1.Name AS FolderNameFROM            dbo.tbl_Products pINNER JOIN dbo.tbl_Products p1ON p1.NodeID = p.ParentNodeID WHERE  p.NavigateUrl <> '#'AND NOT EXISTS(SELECT 1FROM        dbo.tbl_NodeDivisionAssosiation ndaINNER JOIN       dbo.tbl_DivisionAssociation daON da.DivisionID = nda.DivisionIDAND da.UserID = 1WHERE nda.NodeID = p.NodeId)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | magmoAged Yak Warrior
 
 
                                    558 Posts | 
                                        
                                          |  Posted - 2013-08-01 : 03:36:12 
 |  
                                          | Works fine, thank you very much! |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-08-01 : 04:35:02 
 |  
                                          | welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                            
                                |  |