Suppose Column 1 contains values 4, 6, 4, 1, 5 and Column 2 contains values 1, 2, 3, 4, 5, corresponding to the values in Column 1, and I want the highest three values of column 1. How do I do this such that rows 2, 5, and 3 are returned?
            Asked
            
        
        
            Active
            
        
            Viewed 138 times
        
    0
            
            
         
    
    
        adamcircle
        
- 694
- 1
- 10
- 26
2 Answers
1
            Use a composite order by clause with limit to get only the first 3:
select c1, c2
from  t
order by c1 desc, c2 desc
limit 3;
 
    
    
        trincot
        
- 317,000
- 35
- 244
- 286
1
            
            
        Use multiple levels ordering.
e.g SELECT * FROM table ORDER BY column1 DESC, column2 DESC LIMIT 3
sort by column1 first, if ties, use column2 to sort
 
    
    
        sapocaly
        
- 19
- 4