D. Romanski D. Romanski - 11 months ago 28
SQL Question

Finding a salary within a range of 10,000 from the highest salary in SQL

I am using 1 table in this instance, let's just use FName, LName and Salary. I have a feeling I will be using a nested query finding the MAX(Salary). Should I use this in the SELECT statement or the WHERE statement and how to I designate the +/- range?


You're on the right track. Something like this:

FROM MyTable T
WHERE T.Salary > ((
  SELECT MAX(Salary)
  FROM MyTable
) - 10000);

Untested but should work - the idea is to get the max salary, and then select only salaries within 10,000 of the max salary. In other words, select salaries greater than the max salary minus 10,000.