September 23, 2007 at 12:12 am
Hi friedns
1. HOw to find out 2nd highest salary from a table can plz tel me?
2. In my table 10 employees i want 9 th employee sal
3. how to find out least to 2nd sal from emp table can u any body plz explain me:)
September 23, 2007 at 5:13 am
you use a technique using the TOP statement twice:
declare @payroll TABLE (
salary money,
firstname varchar(30) )
INSERT INTO @payroll(salary,firstname)
SELECT 400.01,'Bob' UNION
SELECT 800.02,'Bill' UNION
SELECT 1200.03,'Todd' UNION
SELECT 100.01,'Nick'
SELECT TOP 1 X.salary,X.firstname FROM (
SELECT TOP 2 salary,firstname FROM @payroll ORDER BY salary DESC
) X ORDER BY salary ASC
Lowell
September 23, 2007 at 10:16 am
Sounds a whole lot like interview or homework questions... would have loved to see the reply... "What have YOU tried?" 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
September 24, 2007 at 9:04 pm
|
Sounds like you've nailed it Jeff... The original poster should do a spelling/grammar check prior to submission.
Regards,
Wameng Vang
MCTS
September 24, 2007 at 9:35 pm
Anyone else up for a quick exam question... I'm sure I can dig out a few of them from these forums ;).
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply