Solved

show only first 5

Posted on 2007-11-16
8
543 Views
Last Modified: 2008-02-01
suppose i got some mysql/sql query
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC"

at the moment i view all records with
Do Until rstempo.EOF

how can i show only first 5?

0
Comment
Question by:sasha85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 13

Expert Comment

by:samic400
ID: 20300056

how about a simple counter like this:

dim i
do while not mRS.EOF
   i = i + 1
  if i > 5 then
     exit do
  else
    response.write mRS.fields(yourdata)
loop


0
 
LVL 9

Accepted Solution

by:
CCongdon earned 150 total points
ID: 20300058
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 0, 5"
0
 
LVL 3

Expert Comment

by:BioI
ID: 20300060
add at the end "limit 5":
mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC limit 5"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:samic400
ID: 20300065
do while not mRS.EOF
   i = i + 1
  if i > 5 then
     exit do
  else
    response.write mRS.fields(yourdata)
  end if
 mRS.Movenext
loop
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 20300066
Of course, with mine you might still want to use your loop until EOF construct in case you get back less than 5 records.
0
 
LVL 16

Assisted Solution

by:DrNikon224
DrNikon224 earned 100 total points
ID: 20300067
Rewrite the query to limit to 5 results:

mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 5"
0
 
LVL 13

Assisted Solution

by:samic400
samic400 earned 150 total points
ID: 20300078
Looks like someone beat mean to it:

mySQLo="SELECT id,time,alert FROM TBV where time > DATE_ADD(LOCALTIME(),INTERVAL -2 DAY) ORDER BY time DESC LIMIT 0, 5"
0
 

Author Comment

by:sasha85
ID: 20300103
thank you guys:)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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