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  | 
                             
                            
                                    | 
                                         Dennisvm82 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2011-07-28 : 09:53:52
                                            
  | 
                                             
                                            
                                            Hi guys! I am trying to select some data from a table in an Access 2010 database. The thing was: I wanted to display the latest "Configuration" release of each System (adapter). Well, using the SQL code below it seems to work perfectly, but I am having trouble filtering out the "QaEnv", too.This is what is displayed before the query:ID | QaEnv | System | Type | Configuration | ActiveDate1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-20112 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-20113 | Yankee (UAT1) ACC-V01 | MOMS Adapter | Adapter | 2.4 | 30-06-20114 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.0 | 20-06-20115 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-20116 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.5 | 20-06-2011This is what is displayed after the query:ID | QaEnv | System | Type | Configuration | ActiveDate1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-20112 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-20113 | Yankee (UAT1) ACC-V01 | MOMS Adapter | Adapter | 2.4 | 30-06-20115 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-2011But I want to display this:ID | QaEnv | System | Type | Configuration | ActiveDate1 | Delta (UAT2) EAI-V3 | MOMS Adapter | Adapter | 1.0 | 30-06-20112 | Delta (UAT2) EAI-V3 | GSG Adapter | Adapter | 1.1 | 30-06-20114 | Delta (UAT2) EAI-V3 | KIWI2 Adapter | Adapter | 1.7 | 30-06-2011SELECT t.*FROM Deployments tINNER JOIN(SELECT System, Max(ActiveDate) as ActDateFROM DeploymentsWHERE QaEnv = "Delta (UAT2) EAI-V3" AND Type = "Adapter" AND (([ActiveDate] Between #6/20/2011# And #6/30/2011#)) GROUP BY System) x ON t.system = x.system AND t.ActiveDate = x.ActDate; Can any of you help me out? Thanks in advance,Dennis | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     sunitabeck 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    5155 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-07-29 : 21:17:00
                                          
  | 
                                         
                                        
                                          Add that in a where clause....AND (([ActiveDate] Between #6/20/2011# And #6/30/2011#)) GROUP BY System) x ON t.system = x.system AND t.ActiveDate = x.ActDatewhere t.QaEnv = "Delta (UAT2) EAI-V3"; Not quite clear to me whether I am misinterpreting the sample data. Alternatively, you could add QaEnv in the inner query (for example as max(QaEnv)) and then join on QaEnv in the outer query.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-07-30 : 01:42:07
                                          
  | 
                                         
                                        
                                          | [code]SELECT t.*FROM (SELECT ROW_NUMBER() OVER (PARTITION BY system ORDER BY ActiveDate DESC,Configuration ASC) AS rn,* from Deployments) tWHERE rn=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |