6 replies
by glen_mcleod
Try this (there are probably many others):
Select TOP 1 e1.sal
From emp e1
where e1.sal < (Select Max(e2.sal) From emp e2)
order by e1.sal DESC.
The sub-query will select the max first(1 value), then use it as the criteria for the main query.
This will work in both Access and SQL Server 6.5+, but not in Oracle. In Oracle there's a ROWID property (I think that's what it's called, it's been a while) that will let you limit the number of records returned by using it in the Where clause (ROWID = 1).
You also might try using Max(sal) in the main query instead of TOP 1, I haven't tried it, but it should work.
Glen
by glen_mcleod
Ok, just tried it and it should work anywhere:
Select Max(e1.sal)
From emp e1
where e1.sal < (Select Max(e2.sal) From emp e2)
Glen
by krcshanthi
by simonchan
SELECT MAX(sal) FROM emp
WHERE sal < (SELECT MAX(sal) FROM emp)
by krcshanthi
by krcshanthi
This discussion is closed to new replies.
Trending Software posts
Sort by Trending