if you are only counting rows, then yes, the second is faster, but if you are also using the data, as well as counting, then the first will be quicker than running two queries.
Also, stop suppressing errors on all of your commands. Errors are your friend, fix them, by handling them appropriately.
Last edited by Jenk on Fri Jan 13, 2006 5:08 am, edited 1 time in total.
running two queries is less efficient than running one.. which is kind of obvious
However, running a large query, which will contain a lot of data, only to count just the number of rows, is not as efficent as "SELECT COUNT(*)" as that only returns one cell, not an entire table.
phpmyadmin is your friend, run queries in phpmyadmin and watch the query run time, play around with different stuff to get a feel for how long queries take (complicated joins and subqueries are usually the longest). Also if you have access, use the "top" screen on linux to watch the mysql cpu usage as your queries run
sp2hari wrote:It seems i am just asking how and why in this post.
Again why is there no difference between
Code:
SELECT COUNT(*) FROM `table1`
be slower than
Code:
SELECT COUNT(`Id`) FROM `table1`
Isn't the first case selecting * which must take more time.
You get the query times if you run these queries in the MySQL client. Set a up a test table with over 10,000 rows of dummy data and try both. I haven't tested but I'm inclined to think that the 'select *' is quicker than 'select col' since it doesn't have to look for the specific column, either way it will be negligible.
Select count(*) and count(id) are taking almost the same time
I think i need a bigger database to differentiate or maybe as mentioned earlier by Pimptastic they take equal time