Reporting account (*)

How to make get count (*) in MySQL.

for example, in table 1 I have 10 million records, it has duplicate records.

I want to find out the value of count (*) from the table.

I know i can do

select excellent * from table1 but I don’t want to get 10 million records, I don’t even want to insert individual records into another table, for example, create table table2 select distinct * from table1

So please help me with any other option.

Help someone welcome

+3
source share
3 answers
SELECT COUNT(DISTINCT field) FROM table

or

SELECT COUNT(*) FROM table GROUP BY field;

(btw - this question was received several times elsewhere on this site)

+11
source

Try using a subquery:

SELECT COUNT(*) FROM (SELECT DISTINCT * FROM table1) T1
+4
source

, :

SELECT SUM(cnt) FROM ( SELECT COUNT(*) as cnt FROM tab GROUP BY some_value )
0

Source: https://habr.com/ru/post/1789766/


All Articles