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  | 
                             
                            
                                    | 
                                         misterraj 
                                        Yak Posting Veteran 
                                         
                                        
                                        94 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2008-07-31 : 05:51:10
                                            
  | 
                                             
                                            
                                            | ---------------------Empid  Sno     Salary----------------------  10	1	200010	2	300010	3	400020	4	500020	5	600020	6	700030	7	800030	8	900030	9	10000------------------------I have a table like this, what is want is a result like this10	1	200020	4	500030	7	8000I need only one EmpID for the person with records, the least s.no would be displayed.how would i write the query help please | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     madhivanan 
                                    Premature Yak Congratulator 
                                     
                                    
                                    22864 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 05:55:14
                                          
  | 
                                         
                                        
                                          | Select empid,min(sno) as sno, min(salary) as salary from tablegroup by empidMadhivananFailing to plan is Planning to fail  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     khtan 
                                    In (Som, Ni, Yak) 
                                     
                                    
                                    17689 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 05:55:51
                                          
  | 
                                         
                                        
                                          [code]select Empid, Sno, Salaryfrom   (           select Empid, Sno, Salary,                  row_no = row_number() over (partition by Empid order by Sno)           from   yourtable       ) ewhere  e.row_no = 1[/code] KH[spoiler]Time is always against us[/spoiler]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     khtan 
                                    In (Som, Ni, Yak) 
                                     
                                    
                                    17689 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 05:57:20
                                          
  | 
                                         
                                        
                                          or select t.Empid, Sno, Salaryfrom   yourtable t       inner join       (           select Empid, Sno = min(Sno)           from   yourtable           group by Empid       ) m on  t.Empid = m.Empid           and t.Sno   = m.Sno  KH[spoiler]Time is always against us[/spoiler]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     khtan 
                                    In (Som, Ni, Yak) 
                                     
                                    
                                    17689 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 05:58:23
                                          
  | 
                                         
                                        
                                          quote: Originally posted by madhivanan Select empid,min(sno) as sno, min(salary) as salary from tablegroup by empidMadhivananFailing to plan is Planning to fail
  OP only wanted record with min Sno. Min Sno does not implied min Salary KH[spoiler]Time is always against us[/spoiler]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     misterraj 
                                    Yak Posting Veteran 
                                     
                                    
                                    94 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 06:05:00
                                          
  | 
                                         
                                        
                                          | Everything worked great, thanks to all the members who gave the lighting reply! I m very happy.. thanks once again  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     misterraj 
                                    Yak Posting Veteran 
                                     
                                    
                                    94 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-07-31 : 06:07:05
                                          
  | 
                                         
                                        
                                          | yes i agree Min sNo doesnot implied Min salary, if i had this,Select empid,min(sno) as sno, salary as salary from tablegroup by empidit doesnot work, the last two queries worked great. anyway thanks to all!  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |   
     
     
            
              
	     |  
		
			
     
          
		 |