0
I have a web application that performs several queries, but a Count query is taking 2 seconds to search and return the data to the application. My table where I perform COUNT has about 230 thousand lines with about 20 columns, how can I optimize this query?
SELECT COUNT(*) FROM myTable WHERE status = 1 AND category = 0;
What is the best way to count data in a table with variation in the query?
Anyone who can help me thank you!
Create indexes for status columns and Category
– Rovann Linhalis
$result = mysql_query( "select Count(id) as num_rows from myTable WHERE status = 1 AND Category = 0" );
– user60252
$Row = mysql_fetch_object( $result );
– user60252
$total = $Row->num_rows;
– user60252
source https://stackoverflow.com/questions/116824/whats-the-best-way-to-get-total-of-records-in-a-mysql-table-with-php
– user60252
That one
count(id)
considers possibleid
s null?– Jefferson Quesado
You probably do not have indexes in this column, 230mil records is not a considerable volume of data for a query to be taking.
– arllondias