Solved

First 100 records in a query???

Posted on 2002-05-15
14
205 Views
Last Modified: 2010-05-02
Hello
I have a customer table which contains 2000 records.
I want to view the first 100 records.
How do i do this????

Current Query is
strSql = "Select CustomerName from Customers;"

This shows all the records.

Regards Turlough
0
Comment
Question by:visualbasic
  • 4
  • 4
  • 2
  • +4
14 Comments
 
LVL 1

Accepted Solution

by:
procyn00 earned 50 total points
ID: 7011656
Select Top 100 customerName from customers;
0
 
LVL 1

Expert Comment

by:carpediem
ID: 7011668
It depends on the database you are using.  For many databases procyn00's answer is by far the best answer.  However there are some database that do not support the "Top" syntax.  For those, you will need to find another method.  Often, you may be forced to just loop through the record set and use the first 100.  Of course this isn't very good since depending on the database and how you are retrieving the records often all 2000 records will still be retrieved and brought over the network.
0
 
LVL 5

Expert Comment

by:bob_online
ID: 7011683
You're going to need an order by clause or you risk getting the top 100 random customers.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011708
For a database which does not support "TOP":
'Amount is an integer filed

Select  t1.Amount from Checks t1 where 100> (select
     count(t2.Amount) from checks t2 where t2.Amount>t1.Amount)


Good luck!!
0
 
LVL 1

Expert Comment

by:procyn00
ID: 7011722
If you use a Record ID that increments with every new record or a timestamp field you can just..

Select Top 100 customerName from customers ORDER BY Record_ID_FIELD DESC;
0
 
LVL 1

Expert Comment

by:procyn00
ID: 7011727
What databases do not support the Top Operator? I'm not aware of any and would just like to make note.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7011786
>>What databases do not support the Top Operator? I'm not aware of any and would just like to make note. <<
Top keyword was introduced with SQL Server 7.0, prior versions did not support it.
I am not sure, but I believe it is not supported in either Oracle or MySQL

Anthony


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011802
Paradox for one. Interbase for another. I'm not sure, but I think that VFP doesn't either.


0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011811
Actually, Oracle does support TOP (or at least versions 7.3 and up do). I can't say if MySQL does or not.


0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7011837
Thanks for the correction.

Anthony
0
 
LVL 1

Expert Comment

by:procyn00
ID: 7011851
MySQL Uses Limit

Select customerName from customers LIMIT 100 ORDER BY Record_ID_FIELD DESC
0
 
LVL 10

Expert Comment

by:arana
ID: 7011877
NOP, i'm using oraqcle 7.3.4.3.1 and it DOES NOT support
"TOP"  clause


in oracle you have to do something like :

SELECT Customer, Heading, Priority, DateComposed, TotalActiveDays
FROM
(SELECT Customer, Heading, Priority, DateComposed, TotalActiveDays
FROM TOP20 where Customer='Canada'
and Priority='Minor') where rownum<100 ORDER BY TotalActiveDays desc;


0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011927
Hmmmm... It's been a while, but I am almost positive that I used TOP with version 7.3.x? of Oracle. I know for a fact that it is in 8.x... strange. I'll have to review some of my old code now....<g>

0
 
LVL 5

Expert Comment

by:rpai
ID: 7014669
To view the first 100 records::

strSql = "SELECT CustomerName FROM Customers WHERE Rownum < 101;"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 103
SSRS expression Issue finding a string 10 66
Run code from text file in vb 1 57
Notepad++ how to remove delimiter : from beggning of the line? 3 94
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now