[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

show only first 5

Posted on 2007-11-16
8
Medium Priority
?
553 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
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 600 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 400 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

872 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