Link to home
Start Free TrialLog in
Avatar of bryker
bryker

asked on

Get First N Records

This isn't really strictly a VB question, but I'll try it anyway.

ENVIRONMENT:  VB6 SP-3, ADO 2.1, Oracle 8i.

I need an Oracle-friendly SQL statement that can return the first n records from a given table, using a sort criteria specified by me--or using no sort criteria at all, and relying on the native row ordering.

Selecting the entire rowset, then using GetRows() or something like that isn't really useful.  I could have gajillions of records in this table, and I just need the first 28--and exactly 28.

Is there any way to do this?  Closest thing I know of is "SELECT TOP N PERCENT", but that's a Jet-thing only, besides not fitting the bill anyway.

Seems like I would have heard of something by now if there were a way to do this.  I think it's a no-go.

Thanks in advance for any helpful help.

Avatar of stefanx
stefanx

Bryker, I'd very much like to know this too. Although I don't use Oracle, exactly the same issue exists with SQL Server. Pity that the "SELECT TOP x" thing is Jet specific. You could of course create an MS-Access DB and link the Oracle tables to it through ODBC or OLEDB. Using this would allow you to use the "SELECT TOP x" statement on the Access DB although I would guess it to be a major performance killer.

Perhaps using the trick of sorting the records DESC according to your requirements and using ADO paging might do this, but I'm not that familiar with it.

Anyone else ?
ASKER CERTIFIED SOLUTION
Avatar of NickMP
NickMP

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To Stephan. If you using SQL or Access then your solution is correct. When retrievent x recrods you have to order by asc or desc depending if you want to retrieve them from top to buttom or last to top.
Avatar of bryker

ASKER

Great!  Thanks a lot.  I was wondering why I'd never heard of this--until I tried it in Access...splat!  Can't believe that it's never found its way into Jet.  But as stefanx said, there's a way to do that with SELECT TOP anyway...sort of.

Thanks again.

I quickly checked this out for SQL Server if anyone is interested, it is :

SET ROWCOUNT=28
SELECT * FROM CLIENTS

I quickly checked this out for SQL Server if anyone is interested, it is :

SET ROWCOUNT 28
SELECT * FROM CLIENTS