Q:

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.

A:

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

