Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-24 : 08:30:22
|
Nageshkumar writes "1) Query for finding the Last row of a table.(Assume that you dont know anything about data inside the table)2) Query for finding the second largest salary of a employee in a company." |
|
twhelan1
Yak Posting Veteran
71 Posts |
Posted - 2006-03-24 : 08:38:28
|
[code]SELECT * FROM InterviewQuestionsWHERE Candidate = 'Clueless' AND Questions = 'Pointless'[/code]~Travis |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-03-24 : 10:41:55
|
1) last row is a meaningess concept in a relational database.2) select top 1 salary from (select top 2 salary from tbl order by salary desc) a order by salaryselect max(salary)from tbl where salary < (select max(salary) from tbl)And to utilise v2005 features:with salaries as (select salary, row_number() over (order by salary desc) as sequence from employeesalaries) select salary from salaries where sequence = 2==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-27 : 01:47:50
|
1 You need to define what Last row is (may be Top 1 Order by DESC)2 Select min(sal) from (select top N sal from table order by sal DESC) TMadhivananFailing to plan is Planning to fail |
|
|
|
|
|