Jump to content

SQL Count


avo

Recommended Posts

Hi All

 

How would i please

 

count the number of times a coloum holds a specific (coloums hold the same value)value denoted by the where clause

 

i thought it was like :-

 

$query  = "SELECT customer_name, COUNT(customer_name) FROM serials GROUP BY customer_name WHERE id='".$exploded[0]."' ";

 

Help Appriciated :)

Link to comment
https://forums.phpfreaks.com/topic/86152-sql-count/
Share on other sites

Because of the way you are referencing the customer_name in the query, the results will contain a row for each customer_name, followed by how many times that customer_name is in the result set.

 

To just get a count of the rows, try this -

 

$query  = "SELECT COUNT(*) FROM serials WHERE id='".$exploded[0]."' ";

 

adam291086, program execution is always quicker any time you can get the database to directly produce the answer.

 

Using the COUNT() function in the query means that the database does not need to send all the rows in the result set to php, where php must use memory to store the result resource, just so that the rows can be counted using the mysql_num_rows() function.

Link to comment
https://forums.phpfreaks.com/topic/86152-sql-count/#findComment-440028
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.