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  | 
                             
                            
                                    | 
                                         mindbender 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2011-08-05 : 14:13:03
                                            
  | 
                                             
                                            
                                            | THis is the result I get from running the below queryCCT_NUM   MAJOR_VERSION    STEP_NUM    TYPE    VALUE8           0                11          1      2258           0                14          1      2269           0                1           1      8288           0                6           1      245SELECT t.*FROM cctvariable tINNER JOIN (SELECT c.cct_num, c.value,MIN(c.step_num) AS FirstFROM cctvariable c GROUP BY c.cct_num, c.value)t1ON t.step_num= t1.FirstAND t.cct_num = t1.cct_numAND t.value = t1.valueand t.cct_num in (8,9)and t.major_version = 0and t.type in (1)What I want to return is the minimum step number and only the row with the associated value like belowCCT_NUM   MAJOR_VERSION    STEP_NUM    TYPE    VALUE9           0                1           1      8288           0                6           1      245Any help woudl be appreciated   driving me insane | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     TG 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    6065 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-08-05 : 14:38:35
                                          
  | 
                                         
                                        
                                          I can't tell by your data but I'm guessing that you want this:SELECT t.*FROM   cctvariable tINNER JOIN (       SELECT c.cct_num              ,MIN(c.step_num) AS [First]       FROM cctvariable c       where  c.cct_num in (8,9)       and    c.major_version = 0       and    c.type in (1)       GROUP BY c.cct_num       ) t1       ON t.step_num= t1.[First]       AND t.cct_num = t1.cct_num Be One with the OptimizerTG  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |