Query to find Top N records from an Table w/o TOP function
I want to find out a query for an Oracle database which will give top n records
suppose I have a Employee table which has 4 fields viz. Ename,Age,Dept &
Salary, now I want to find Top three salaries from Table which query will
be most appropriate?
Re: Query to find Top N records from an Table w/o TOP function
"Kedar" <email@example.com> wrote in message <news:firstname.lastname@example.org>...
> I want to find out a query for an Oracle database which will give top n records
> from table.
> suppose I have a Employee table which has 4 fields viz. Ename,Age,Dept &
> Salary, now I want to find Top three salaries from Table which query will
> be most appropriate?
Maybe you can do a self-join with grouping: (untested)
select employee.id, min(employee.name), min(employee.salary)
from employee, employee as e
where employee.salary <= e.salary
group by employee.id
having count(*) <= n
Joe Foster <mailto:jlfoster%40znet.com> Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL