View Single Post
Old 01-17-2010, 07:22 PM  
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
SELECT COUNT(*) FROM `john` WHERE `status` = 1

It's always a good idea to backtick fields. Also, don't put INT fields in quotes - it will slow your query down by up to 60%.

Note, this method of counting rows has fundamental restrictions. If you have 100 items, and use LIMIT - count will only return the number of LIMIT'd rows.

If you want to always have a count of ALL rows that matched the query:
SELECT SQL_CALC_FOUND_ROWS * FROM `john` WHERE `status` = 1

Pulling the resulting count out will require another query, but your DB abstractor should take care of it
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote