|
View previous topic :: View next topic
|
| Author |
Message |
chandracdac
New User
Joined: 15 Jun 2007 Posts: 92 Location: bangalore
|
|
|
|
| i want to retrieve first 3 records of my table without using cursor . can anybody help me? |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
There is no such thing as "the first 3 records" in an active database table.
How would you define the first 3? |
|
| Back to top |
|
 |
jaspal
New User
Joined: 22 May 2007 Posts: 68 Location: mumbai
|
|
|
|
in cobol we can't retrieve more than one record without cursor
regards,
Jaspal |
|
| Back to top |
|
 |
acevedo
Active User

Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
then use 3 selects.
select fields from yourtable
FETCH FIRST 1 ROW ONLY
select fields from yourtable
where key>lastkey
FETCH FIRST 1 ROW ONLY
select fields from yourtable
where key>lastkey
FETCH FIRST 1 ROW ONLY |
|
| Back to top |
|
 |
stodolas
Active Member

Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
| acevedo, what if the clustering index is different than the primary key? |
|
| Back to top |
|
 |
acevedo
Active User

Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
| dick scherrer wrote: |
Hello,
There is no such thing as "the first 3 records" in an active database table.
How would you define the first 3? |
if you join Dick answer to your answer then my conclusion is:
only the OP knows what he's trying to get...
and if my previous post you add ORDER BY WHATEVERYOURKEYFIELDHERE....then.. it should work. |
|
| Back to top |
|
 |
stodolas
Active Member

Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
| No one ever defines what they want other than the "first x rows" or "second y rows". These types of statements are no good in a database. The concept is just wrong in a database world. If they would say the "first x rows ordered by my primary key where the key is > xxx" then we could give them a sensible answer. But no one ever does. |
|
| Back to top |
|
 |
acevedo
Active User

Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
| stodolas wrote: |
| No one ever defines what they want other than the "first x rows" or "second y rows". These types of statements are no good in a database. The concept is just wrong in a database world. If they would say the "first x rows ordered by my primary key where the key is > xxx" then we could give them a sensible answer. But no one ever does. |
simply... right! |
|
| Back to top |
|
 |
|
|