Hello Friends ,
Recently few of my friends was looking for a job during them interviews one comman question asked to them is the get or find the Nth value form the any table like Employee table.
so here is the one query which will give you Nth value from the employee table.
1) SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
2) Select top 1 Name, Salary From Employees Where Salary Not In (Select Distinct Top 4 Salary From Employees order by Salary desc) order by Salary desc
3) SELECT TOP 1 Mark FROM (SELECT TOP {N} Mark FROM Student ORDER BY Mark DESC) AS E ORDER BY Mark ASC
Where {N}= 2,3,4,5 etc
Eg: For 4th Highest Mark {N}=4
Enjoy friends
This entry was posted
on Monday, July 20th, 2009 at 5:21 am and is filed under Sql Server.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Hello ! I am Arjun Jadeja a Software Engineer by Profession. You can contribute and I will distribute your ideas through this site. Thanks and Enjoy
Leave a reply