Faster way to count how many records I have in a MYSQL table

0

As the title says, I wanted to know which is the fastest way to count records from a table with thousands of records.

    
asked by anonymous 17.06.2015 / 15:00

2 answers

1

I think the easiest way is using COUNT, I use it daily and I have never had problems and use on large bases.

The COUNT (*) function returns the number of records in a table:

SELECT COUNT(*) FROM table_name;

The COUNT (DISTINCT column_name) returns the number of distinct values in the specified column:

SELECT COUNT(DISTINCT column_name) FROM table_name;
    
17.06.2015 / 15:10
1

You can use the count () function to do this.

SELECT COUNT(*) FROM tabela

and you can also do this by using filters from your tables to bring only what interests you:

SELECT coluna1, coluna2, COUNT(*) FROM tabela
WHERE coluna1 = 'dado' OR coluna2 = 'dado'
GROUP BY coluna1, coluna2;
    
17.06.2015 / 15:11