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  | 
                             
                            
                                    | 
                                         lmnorms1 
                                        Starting Member 
                                         
                                        
                                        7 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2008-05-16 : 17:56:40
                                            
  | 
                                             
                                            
                                            | I have some data I want to retrieve. Select Agent.AgentName as AgtNme,agent.License as AgtLic,from agent;(Plus about twenty other fields). This will give me the agent information. But I get duplicates. Doing distinct will give me about 5338 out of 62500. But doing group by does not work. If I do a group by only on license I get 5284 records returned. Why the theoretical differences in retrieving based on license?How can I ensure I am getting only one record for each Licensed agent? Any advice is appreciated.Thank you,Lmnorms1 | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     RickD 
                                    Slow But Sure Yak Herding Master 
                                     
                                    
                                    3608 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-05-19 : 02:10:50
                                          
  | 
                                         
                                        
                                          | If you do a distinct on your query, you are saying AgentName & License need to be distinct, this means that there may have been more than 1 agent inserted per license. When you group by just the license, then you will only get distinct license numbers, regardless of whether the agent name is the same or not.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     lmnorms1 
                                    Starting Member 
                                     
                                    
                                    7 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2008-05-22 : 14:04:30
                                          
  | 
                                         
                                        
                                          | Thank you. That's what I was thinking...that if I do distinct the possibility of unique agents might get lost based on spelling. But if I do distinct on license or group by license then I might get a closer approximation of an accurate number. Thank you for the information.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |