In this article, I want to show an innovative solution to a common problem. Find the records in the table with the maximum value in one of the columns.
For example, we will look for employees with the highest salary.
The standard solution is to find the maximum value in the salary column and then use that as a filter.
where salary = (select max(salary) from employees);
However, the SQL:2008 standard offers a new solution to this problem: FETCH FIRST … ROWS WITH TIES
order by salary desc
fetch first 1 rows with ties;
With the same success, using the FETCH FIRST … ROWS WITH TIES construction, the problem of finding N maximum and minimum values is easily solved, the solution of which in other ways is no longer so trivial