As the title says, I wanted to know which is the fastest way to count records from a table with thousands of records.
As the title says, I wanted to know which is the fastest way to count records from a table with thousands of records.
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;
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;