Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2005, 06:42 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default retrieve everything AND count rows in one hit

Code:
set rsminmax = con.execute("SELECT * FROM `minirules_minmax` where RuleId = '" & contractId & "'")
set rsminmax2 = con.execute("SELECT COUNT(*) FROM `minirules_minmax` where RuleId = '" & contractId & "'")
Is there any way to do this in one SQL query?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old October 27th, 2005, 11:44 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure if it will work, but try using HAVING clause instead of WHERE. Also, try HAVING ... IN ...
JOHN

 
Old October 28th, 2005, 02:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What I think you want to do is use a GROUP BY on the RuleId field, specifying a RuleId='x,y, or z', along with a call to the COUNT() function in your query.

Try:
SELECT *,COUNT(*) FROM `minirules_minmax` where RuleId = '" & contractId & "'" GROUP BY RuleId;

You can also do things with SUM() and MAX() in this type of query, as well. For instance, on the User table in the mysql database:

mysql> SELECT Insert_priv,SUM(IF(host!='localhost',1,0)) FROM `user` where user!= 'root' GROUP BY Insert_priv;
+-------------+--------------------------------+
| Insert_priv | SUM(IF(host!='localhost',1,0)) |
+-------------+--------------------------------+
| N | 1 |
| Y | 4 |
+-------------+--------------------------------+

Immediately, you see four remote users of your DB with insert privileges, and 1 (probably user='') with none.
 
Old January 18th, 2006, 06:42 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks Daniel and jmoronilla, i'll try it

www.crmpicco.co.uk
 
Old January 18th, 2006, 01:02 PM
Authorized User
 
Join Date: May 2004
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

Where are you calling this from?

In PHP for example one the call has been made you can query mysqli_affected_rows to see how many rows were returned.

 
Old January 20th, 2006, 06:02 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

it is being called from within an Classic ASP page, sorry PHP is not involved

www.crmpicco.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hit-count for dynamic page Steve777 ASP.NET 2.0 Basics 2 June 24th, 2008 11:09 AM
Application Hit Count jayakumar.cj ASP.NET 1.0 and 1.1 Basics 1 July 15th, 2006 06:05 AM
Trying to retrieve top 1 for multiple rows MonicaM SQL Language 2 May 16th, 2006 03:29 AM
Hit Count rajuru PHP Databases 1 November 1st, 2004 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.