I have 2 points.
if i need to count record (PHP AND MYSQL), which way is the best one. (timing case)
"select count(*) from table where id = xxx"
"select * from table where id = xxx" and using mysql_numrows to get record count
Thanks
SELECT COUNT(id) AS total WHERE id='xxx'
will give you the smallest overhead IMHO.
-Jon
Yes, this is because the SELECT COUNT() should only store an int whereas the SELECT has to keep the data for all the records that match the criteria. You can imagine that might be significant memory usage.
If all you want is the count of rows then count(*) is the way to go.
All it returns is the "count" so you're not asking the db to return a whole bunch of data.
I haven't benchmarked it, but I'm certain it's quicker for a simple row count.