Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Difference between rowid and rownum in sql query??

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In sql query what is the difference between rowid and rownum ?

As I know that :

rowid is the unique index number of every row of table maintaining by database automatically.

rownum is the sequential number of rows in the resultset object.

But my confusion is if I write query like below for extracting 1st row

select * from table_name where rownum = 1 Then it is working fine

But if I write query like below for extracting 3rd row

select * from table_name where rownum = 3 Then it is returning zero row.

for that i have to write query like below

select * from table_name where rowid in(
(select rowid from table_name where rownum <= 3)
minus
(select rowid from table_name where rownum < 3)
)

Can any one please clarify me.

Thanks & Regards
Bikash
[ June 03, 2004: Message edited by: Bikash Paul ]
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rownum is usually used to restrict the number of rows that are returned(due to obvious web based result restrictions like u can process only certain number of rows).

but the followingtip may give you more insight into this issue.

Remember that you can always use google to understand these technical issues quickly.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Assuming we 're talking Oracle:

- ROWID is a semi-physical value specifying the location of a row (in terms of data file, extent, etcetera). ROWID is not very useful in day-to-day programming, as it is not a constant value (it changes with table re-organizations, imports, and things like that). Therefore it requires caution in its use.
- ROWNUM is a logical value for the sequence of row retrieval in the resultset. This is the position before sorting, so rownum is not always the same as the position in the resultset presented to you. This also requires some caution.

Hope this helps,

Rudy.
 
    Bookmark Topic Watch Topic
  • New Topic