English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

You can do a Select query on a Select Query.

The first SELECT query returns a decending sort on salary and will return only X (2 in this case) records by using the TOP modifier (SELECT TOP 2)

You can run a second query on the first. If you use Access summation options in the query designer then you can specify FIRST or LAST record. LAST inthis case will be the second highest.

You can also reverse the sort direction to ACENDING and return the TOP 1 which will also be the second highest salary

2007-03-10 12:57:10 · answer #1 · answered by MarkG 7 · 0 0

The answer really depends on what database you are using, they don't all provide the same features.

You could try something like:

SELECT MIN salary FROM (SELECT TOP 2 salary FROM emp ORDER BY salary DESC)

This isn't particularly elegant, but if your database provides a 'TOP n' or 'FIRST n' it might do the job.

2007-03-10 20:10:53 · answer #2 · answered by codesuidae 1 · 0 0

select max(salary) from emp
where salary < (select max(salary) from emp)

2007-03-11 01:32:42 · answer #3 · answered by Serge M 6 · 0 0

fedest.com, questions and answers