List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:March 14 1999 12:17pm
Subject:Re: select count distinct
View as plain text  
>>>>> "Scott" == Scott Liu <scott@stripped> writes:

Scott> ChinaConnect wrote:

>> Hi,
>> In mysql, it doesn't look like you can do this:
>> select count(distinct id) from sometable.
>> 
>> If this is true, how would I count the number of times distinct ids occur?
>> 
>> 

Scott> I noticed that, too. What I did is to "select id from sometable" and then
Scott> count the
Scott> distinct id in the application program. Can anyone give us a better way to do
Scott> this?

Scott> Scott

Until MySQL 3.23:

CREATE TABLE tmp_table_$$ (distinct_value CHAR(x), PRIMARY KEY (distinct_value));
INSERT IGNORE INTO tmp_table SELECT distinct_value FROM table_name;
SELECT count(*) from tmp_table_$$;
drop table tmp_table_$$;

Regards,
Monty
Thread
AUTO_INCREMENT Limits to 256 recordsKevin P. O'Brien11 Mar
  • Re: AUTO_INCREMENT Limits to 256 recordsMicheal Mc Evoy11 Mar
  • one query for two identical tablesTao Liang3 Mar
    • RE: one query for two identical tablesNicolas Prade3 Mar
  • group by conditionsTao Liang5 Mar
    • Re: group by conditionssinisa6 Mar
      • accessing db while updating itTao Liang26 Mar
Re: AUTO_INCREMENT Limits to 256 recordsKevin P. O'Brien11 Mar
  • Re: AUTO_INCREMENT Limits to 256 recordsRobert Hazeltine11 Mar
Re: AUTO_INCREMENT Limits to 256 recordsKevin P. O'Brien11 Mar
  • select count distinctChinaConnect11 Mar
    • Re: select count distinctChris12 Mar
    • Re: select count distinctScott Liu13 Mar
      • Re: select count distinctMichael Widenius15 Mar
  • Re: AUTO_INCREMENT Limits to 256 recordsChristian Mack12 Mar
Re: AUTO_INCREMENT Limits to 256 recordsKevin P. O'Brien11 Mar
Re: AUTO_INCREMENT Limits to 256 recordsEd Carp12 Mar
Re: AUTO_INCREMENT Limits to 256 recordsEd Carp13 Mar
Re: Bad handshake problem with java and MySQL 3.22.32Carlos Proal15 Feb