• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Difference between rowid and rownum in sql query??

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic