472,353 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 87140
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...
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...
0
by: Subba Rao via DotNetMonster.com | last post by:
---------------------------HTML---------------------------------------- <html> <head> <title>:: DHTML Table Demo ::</title> <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?...
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...
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...
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....
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,...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.