What will be the optimized query for pulling out various columns of a row which HOLDS a minimum value for a particular column.
For e.g Displaying Name and the salary of all the persons which holds the minimum salary in the category of Permanent Employees from the below table which has just three columns in it
Employee (Name, EmployeeType, Salary)
EmployeeType Can be Permanent or Temporary
I already know a solution but I think there might be a better way.
My solution is :
Select E.* from Employee Where
Salary = (Select Min(Salary) From Employee Where EmployeeType='P')
and EmployeeType='P'
If the minimum salary is shared by more than one employee, you can retrieve all of them using the
TOP (1) WITH TIESconstruct:Reference: