tags:

views:

244

answers:

3

whats the syntax in getting the total number of rows in a particular table in an mysql database?

+10  A: 

I've always done

SELECT count(*) from table

The above will you give you the total count of all rows.

You could just as easily tack on a WHERE clause to get the count of some subset

SELECT count(*) from table WHERE foo = 'bar'
Mark Biek
+2  A: 
SELECT count(*)
FROM table_name
+2  A: 

COUNT(*) facts and myths:

MYTH: "InnoDB doesn't handle count(*) queries well":

Most count(*) queries are executed same way by all storage engines if you have a WHERE clause, otherwise you InnoDB will have to perform a full table scan.

FACT: InnoDB doesn't optimize count(*) queries without the where clause

Charles Faiga
That would make it not a true myth, but something that is is true under limited circumstances only, including the circumstance in the original question: getting a count of all rows in a table.
thomasrutter