简体   繁体   中英

Limit not working on count distinct? mysql

I have this to count how many messages an user has:

SELECT count(distinct `from`) FROM chat WHERE `to`=? and recd='0' limit 100

it is retorning 120.418. The limit 100 is not working. any ideas?

if an user has more than 100 messages I'd like to count only 100.

Here the way to go... You need 2 Selects

 SELECT COUNT( A.`from` ) FROM ( SELECT DISTINCT `from` FROM chat WHERE `to`=? and recd='0' limit 100 ) A

Sorry, it was not tested. Now its working

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