View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 09:26 AM
Chris
 
Posts: n/a
Default Re: How to count unique values in a column?

Robert Klemme wrote:
> On 19.03.2007 18:11, Chris wrote:
>> How do I count the unique values in a column in a very large table?
>>
>> I could do this:
>>
>> select mycolumn
>> from mytable
>> group by mycolumn;
>>
>> and wait to see how many rows come back. The trouble is that the table
>> has 75 million rows, and the MySQL Query Browser crashes with an
>> out-of-memory error after 5 million rows have come back.
>>
>> All is need is a single number: the count. There's got to be a way to
>> do it in SQL alone.

>
> count(distinct mycolumn)
>
> robert


This indicates the right syntax:

http://dev.mysql.com/doc/refman/5.0/...functions.html

But I tried:

select count (distinct session_id) from event_test;

and got:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'distinct
session_id) from event_test at line 1.

The table and the column name is correct. What am I doing wrong?


Reply With Quote