How to get Top 1 and Bottom 1 Records

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 243
Hi,here is the query to get top 1 and bottom 1 records:-

SELECT *
FROM EMPLOYEE_MASTER
WHERE EMP_ID IN(
SELECT TOP 1 MIN(EMP_ID) EMPLOYEE_ID
FROM EMPLOYEE_MASTER

UNION ALL

SELECT TOP 1 MAX(EMP_ID) EMPLOYEE_ID
FROM EMPLOYEE_MASTER);

Comments or Responses

Login to post response