javad75
javad75

Reputation: 1435

Calculate number of table rows in mysql

I have a mysql table with up to 2.000.000 Records

How can in the fastest time calculate the number of rows in the table?

Upvotes: 0

Views: 148

Answers (4)

Brian Ridgeway
Brian Ridgeway

Reputation: 255

For exact count for all storage engines:

select count(*) from table1;

For faster MyISAM exact count or InnoDB estimated count:

show table status;

or

select table_schema, table_name, table_rows from information_schema where table_name = 'table1' and table_schema = 'schema1';

see MySQL show status documentation

see MySQL infromation_schema.tables documentation

Upvotes: 1

Zohaib Aslam
Zohaib Aslam

Reputation: 595

SELECT COUNT(*) FROM table_name; is the fastest way to calculate the numbers of rows because it uses column indexes. if you're using MyISAM engine then it actually stores row count and it doesn't count rows each time you issue SELECT COUNT(*) FROM table_name Further Clarification is here

COUNT(*)

Upvotes: 0

user3349436
user3349436

Reputation: 151

This fastet

SELECT COUNT(1) FROM `sometable` WHERE somefield = 'somecondition'

Upvotes: 0

Jakob
Jakob

Reputation: 1129

SELECT COUNT(1) FROM table_name

Upvotes: 0

Related Questions