Home » SQL & PL/SQL » SQL & PL/SQL » Hlp in Qry
Hlp in Qry [message #8668] Wed, 17 September 2003 23:42 Go to next message
Cindreen Clarence
Messages: 41
Registered: March 2003
Location: Bangalore
Member
Hi All,
Could any1 pls tell me 'How 2 retrieve every 3rd record of a table'?
thank u.
Re: Hlp in Qry [message #8675 is a reply to message #8668] Thu, 18 September 2003 04:22 Go to previous messageGo to next message
R.Satish Kumar
Messages: 14
Registered: August 2003
Junior Member
Hi,

select * from
(select empno,rownum rm from emp) a
where mod(a.rm,3) = 0;

Hope this will solve your query..

Regards,
Satish.R
Re: Hlp in Qry [message #8677 is a reply to message #8668] Thu, 18 September 2003 05:20 Go to previous messageGo to next message
Ani
Messages: 56
Registered: November 2000
Member
select * from table_name
where rowid in
(select rid from
(select rowid rid, rownum rn from table_name)
where mod(rn,3) = 0)
Re: Hlp in Qry [message #8683 is a reply to message #8668] Thu, 18 September 2003 07:54 Go to previous messageGo to next message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
Cini,
How do you define '3rd record of a table' ?
Oracle may not return results in any predictable order ,unless you (explicit or implicit) order them by specific column(s)

Rowid tells you the physical location of a record in terms of File#,Block#,Record# and MAY BE REUSED and CHANGED internally, hence providing no guarantee.

Rownum assigns row numbers as they are returned in a result set. You cannot get ROWNUM=3;

You will have to specify the criteria for ordering rows in your result set.

Hope this helps
Thiru
I totaly agree with Thiru [message #8695 is a reply to message #8683] Fri, 19 September 2003 03:17 Go to previous message
Mike
Messages: 417
Registered: September 1998
Senior Member
I totaly agree with Thiru.
The 2 other given solution may seem to work but in fact they are not correct for the reason given by Thiru.
Previous Topic: error message -ORA-01631 max # extents (string) reached
Next Topic: Java.exe Error
Goto Forum:
  


Current Time: Tue Apr 23 12:07:08 CDT 2024