Forum Moderators: coopster

Message Too Old, No Replies

How to Count Distinct Variable

         

omoutop

3:36 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi to all!
Is there a way to count a distinct variable...
i.e.
Something like that but distinct?

$CountLocations = "select count (Location) as Location from Scores where Flag='A'";
$CountLocations2 = mysql_query($CountLocations);
$CountLocations3 = mysql_result($CountLocations2, 0, "Location");

Thx in advance

arran

4:43 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



select count(distinct Location) as Location from Scores where Flag='A'

should work, although i think using count and distinct together requires a newish version of mysql.

If that doesn't work, you could use:

select Location, count(Location) as loc_num from Scores where Flag='A' group by Location

then count the number of rows returned.

arran.

omoutop

7:16 am on Aug 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thx Arran,

select count(distinct Location) as Location from Scores where Flag='A' ...worked fine for me

Thx again!