-
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?
-
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|