On Sa, 1999-03-20 11:25:51 -0700, Thimble Smith wrote:
> COUNT(DISTINCT(...)) doesn't work in MySQL (yet). Try this:
>
> SELECT COUNT(*) FROM table GROUP BY ip;
Not again! I really wonder why people keep on giving this wrong
answer ...?
Thimble, this query only gives how many of each distinct value you
have, but not the number of distinct values.
The right answer is that it's not possible to do
SELECT COUNT(DISTINCT field) ...
or equivalent with a single SQL query using MySQL up to 3.22.20a.
But, if you're not restricted to the SQL level only, as in most cases
where you use some host language to handle your queries, look at the
function mysql_num_rows() in MySQL's API. If you can access this
functionality with your host language, then just
SELECT DISTINCT field FROM table;
and then get the number of results.
Regards,
Martin
--
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26 E4 EC 80 58 7B 31 3A D7
| Thread |
|---|
| • Help with query, plz | Michal Ludvig | 20 Mar |
| • Re: Help with query, plz | Thimble Smith | 20 Mar |
| • Re: Help with query, plz | Michal Ludvig | 20 Mar |
| • Re: Help with query, plz | Martin Ramsch | 20 Mar |
| • Re: Help with query, plz | Ed Carp | 20 Mar |
| • Re: Help with query, plz | Michal Ludvig | 20 Mar |
| • Re: Help with query, plz | Thimble Smith | 20 Mar |
| • Re: Help with query, plz | Ed Carp | 20 Mar |
| • Re: Help with query, plz | Martin Ramsch | 20 Mar |
| • Re: Help with query, plz | Ed Carp | 20 Mar |