How to use MAX () for multiple occurrences of Max values ​​in SQL

Does the MAX () function return only the first occurrence of the maximum value it encounters? What happens if there are multiple occurrences on different lines of the same maximum value? Is there a way to get all of these strings using the MAX () function? Please, help!

+4
source share
1 answer

MAX() - the scalar function returns a single value and does not write so if you have several records with a maximum value of the same value, the following will still return only one value:

SELECT MAX(Value) FROM MyTable

If you want to get all records with maximum value, you can use

SELECT * FROM MyTable
WHERE Value = (SELECT MAX(Value) FROM MyTable)
+11

Source: https://habr.com/ru/post/1530799/


All Articles