I have a query that returns the biggest difference in two columns. Lets say it’s something like:
| result |
5
5
5
4
4
3
2
How can I make it return all of the top results every time? (5, 5, 5)
I’m not looking for LIMIT 3, since the results vary and sometimes there’s only one top number, etc.
The query I have now looks like this:
SELECT MAX(column1 - column2) as result
FROM table
WHERE othercolumn = somecondition
GROUP by id
ORDER BY results asc
1 Answer