473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Top 10 Rows

how i retrive top or bottom 10 rows in a table in oracle ?
give select statement ...
Apr 12 '07 #1
7 87411
chandu031
78 Expert
Hi,

This query will return the top 10 rows..

select col1,col2 from (select rank() over (order by col1) r , col1,col2 from TABLE) where r<11



For bottom 10 rows use

select col1,col2 from (select rank() over (order by col1 DESC) r , col1,col2 from TABLE) where r<11


Hope this helps..............
Apr 12 '07 #2
masdi2t
37
how i retrive top or bottom 10 rows in a table in oracle ?
give select statement ...

for top row just use the magic column rownum

SELECT * FROM your_table WHERE rownum <= 10;

if you want bottom row you can order it before (using ORDER BY your_field DESC)
Apr 13 '07 #3
Sandya
7
how i retrive top or bottom 10 rows in a table in oracle ?
give select statement ...

select top 10 column name from table name
Apr 13 '07 #4
Sandya
7
how i retrive top or bottom 10 rows in a table in oracle ?
give select statement ...
/* it fetch u top 10 elements */
select top 10 column name from table name order by column name desc

/it vl fect u bottom 10 elements */
select top 10 column name from table name order by column name asc
Apr 13 '07 #5
Sandya
7
how i retrive top or bottom 10 rows in a table in oracle ?
give select statement ...

v can use top in sqlserver 2000
but it is not possible in oracle


it vl fetch u data of top 10 elment

select columname from tablename group by rownum ,column name
having rownum >enter the rownum above which u want
order by rownum ,colum name desc
Apr 13 '07 #6
chandu031
78 Expert
Hi ,

As Sandya pointed out there is no TOP function in Oracle(atleast till version 9i)..
So you can either use a rank() function or use rownum.

And one clarification ...
Use rank() over(order by column desc) for top 10 rows and
rank() over(order by column) for bottom 10 rows...

And if you have contention between two or more rows and you want all of these rows to be displayed , then use Dense_rank() function. For example if you have four people with salaries like this:

NAME SALARY
A 1000
B 2000
C 3000
D 3000

Now using rank() to get top 3 rows will return
D 3000
C 3000
B 2000

whereas using dense_rank() will return all rows
D 3000
C 3000
B 2000
A 1000


Hope this is helpful..........
Apr 13 '07 #7
hetesp
1
Hi,

Simplest way is:

select * from emp where rownum <= 10 order by rownum asc;

But if you need to compare the information retrieved, use MINUS .. you may use:

select * from emp e ,( select empno,rownum num from emp order by 1 asc) x
where E.EMPNO = x.empno
and x.num <= 10;


Hope it helps.

Cheers,
Paul
Feb 19 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
6
by: dddddddd2444444 | last post by:
Hi,please help... It works fine when I define a 2-D array like char code. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why?...
0
by: Subba Rao via DotNetMonster.com | last post by:
---------------------------HTML---------------------------------------- <html> <head> <title>:: DHTML Table Demo ::</title> <script langauge="javascript" src="InterchangeRows.js"></script>...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
by: rn5a | last post by:
All the rows in a DataGrid are accompanied by a CheckBox. When a user checks the rows & clicks a Button, the checked rows get deleted. For e.g. assume that the DataGrid displays 10 rows. A user...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
2
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.