If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > SQL Counts or Application Counts?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-09, 16:07
roland23 roland23 is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
SQL Counts or Application Counts?

Hi,

Is it usually preferable to do several SQL counts on a related set of data or to pull all the data into the PHP app with 1 SQL statement and do the counts in php?

I need to peform 4 counts on a similar set of data. I would probably have to read about 100,000 rows into memory to count the data in PHP.

I'm guessing it's better to just do several SQL statements --all counts--, but maybe someone has some experience on the subject. Perhaps, it's possible to do all the counts in one statement, but I haven't figured out a way.

-r23
Reply With Quote
  #2 (permalink)  
Old 04-13-09, 16:52
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
assuming you are using a server SQL (eg MySQL) rather than a file base SQL (eg JET or Filemaker) then it should be far better to do the summation using SQL on the server, rather than doing it using PHP and iterating through a recordset.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-13-09, 22:37
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
you need only one query to get your different counts

i'd show you, but unfortunately my beta copy of Microsoft® CrystalBall© is down at the moment, and i can't really see what your 4 counts are supposed to be

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 04-14-09, 09:35
roland23 roland23 is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Haha, thanks for the offer. After some research, I think I can get the counts I need using CASE and SUM. Previously, I have only used count and group by. If I hit a brick wall, I'll post some more detailed information.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On