MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 11th, 2000, 05:19 PM
elin elin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 20 elin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am attempting to count the number of distinct users in a table where a user can be expected to have multiple records.

Here's what I did:

mysql> select distinct user from CE_TRACKER;
+-----------+
| user |
+-----------+
| david |
| dkaris |
| eel |
| patsi |
| testeel |
| testeel33 |
| testeel37 |
+-----------+
7 rows in set (0.01 sec)

mysql> select count(distinct user) from CE_TRACKER;
ERROR 1064: You have an error in your SQL syntax near 'distinct user) from CE_TRACKER' at line 1

The example given in the documentation exactly matches what I did here:

COUNT(DISTINCT expr,[expr...])
Returns a count of the number of different values.

mysql> select COUNT(DISTINCT results) from student;

Where oh where have I gone wrong? Thanks for any help.

Reply With Quote
  #2  
Old April 11th, 2000, 08:19 PM
jeffk jeffk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 1 jeffk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
As of MySQL 3.23.2 you are able to use the command you used "mysql> select count(distinct user) from CE_TRACKER;" . Anything before doesn't allow you to use distinct with count as you did. I hope that helps you.

Reply With Quote
  #3  
Old April 11th, 2000, 08:52 PM
elin elin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 20 elin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Aha! That was it. Thanks much.

Reply With Quote
  #4  
Old April 13th, 2000, 09:45 AM
PAV PAV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Netherlands
Posts: 77 PAV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by elin:
Aha! That was it. Thanks much.[/quote]

Until that new version, why don't you use:

select count(user) from CE_TRACKER group by user;

It should give you the same results.

Reply With Quote
  #5  
Old April 13th, 2000, 11:54 AM
elin elin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 20 elin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It doesn't. That gives me the number of rows belonging to each distinct user, but doesn't count the number of users having rows.

Reply With Quote
  #6  
Old April 14th, 2000, 09:50 AM
PAV PAV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: Netherlands
Posts: 77 PAV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by elin:
It doesn't. That gives me the number of rows belonging to each distinct user, but doesn't count the number of users having rows.[/quote]

You're so right, I had a bit of a black-out
So until the next version there's nothing left to do just a select distinct user from CE_TRACKER; and then count the number of returned rows (or do a $mysql_num_rows in PHP)

Nice cracker, I liked it!

Peter

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > using COUNT(DISTINCT column)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway