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  | 
                             
                            
                                    | 
                                         ywb 
                                        Yak Posting Veteran 
                                         
                                        
                                        55 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2005-12-19 : 16:50:37
                                            
  | 
                                             
                                            
                                            | Hi,How do I take only the top 5 entries of a UNION statement?For example, I have a query  SELECT * FROM userTable WHERE (condition 1)  UNION  SELECT * FROM userTable WHERE (condition 2)  UNION  SELECT * FROM userTable WHERE (condition 3)  ORDER BY usernameAnd I only want only the top 5 of this. How can I do it?Thanks,W. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     rockmoose 
                                    SQL Natt Alfen 
                                     
                                    
                                    3279 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2005-12-19 : 16:59:14
                                          
  | 
                                         
                                        
                                          | select top 5 from userTablewhere (condition 1) or (condition 2) or (condition 3)order by uername-----------------------------------------------------select top 5 * from(SELECT * FROM userTable WHERE (condition 1)UNIONSELECT * FROM userTable WHERE (condition 2)UNIONSELECT * FROM userTable WHERE (condition 3)ORDER BY username) as unionedResultWhy We Be?____________________________________knowledge comes with death's releaserockmoose  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     ywb 
                                    Yak Posting Veteran 
                                     
                                    
                                    55 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2005-12-19 : 17:16:04
                                          
  | 
                                         
                                        
                                          | Thanks!  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |