简体   繁体   中英

distinct count(*)

How to do get distinct count(*) in MySQL.

for example, in table1 i have 10 million record, there are duplicate records in it.

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

I know, I can do

select distinct * from table1 but, i don't want to fetch 10 million records, not even want to insert distinct records in other table like, create table table2 select distinct * from table1

So, please help me with any other option.

Help from anyone welcome

SELECT COUNT(DISTINCT field) FROM table

or

SELECT COUNT(*) FROM table GROUP BY field;

(btw - this has been answered quite a few times elsewhere on this site)

尝试使用子查询:

SELECT COUNT(*) FROM (SELECT DISTINCT * FROM table1) T1

也许喜欢:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM