DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Kedar Guest

    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
    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?

  2. #2
    Joe \Nuke Me Xemu\ Foster Guest

    Re: Query to find Top N records from an Table w/o TOP function

    "Kedar" <kedar_aj@hotmail.com> wrote in message <news:3bf65d24$1@147.208.176.211>...

    > 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!



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links