Skip to content
Advertisement

Select max entries in a range in SQL server

I have a salary column where I have to select between range of 10000 and 20000 and also the top rows of max salary.

Column I have:

Rows I want to select

I can use top n rows but that will apply on to this column. What I want to do is, say if this column has 2 rows that has max salary, it would select 2, but if another column has 5 rows that has max salary like below, then it should select 5. column I have:

rows I want to select:

my sql statement:

This statements only returns 1 row.

Advertisement

Answer

You may use TOP 1 WITH TIES here:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement