Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Count UNIQUE

Quote Reply
Count UNIQUE
Hi:

I know how to run count-

my $total = $DB->table('Links')->count ( Field_Name );

but is there an easy way to count the number of UNIQUE entries for that field?

Thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] Count UNIQUE In reply to
I believe you can do:

$DB->table("Links")->select("count(distinct(field))")->fetchrow();

works from SQL monitor...

Code:
select count(distinct(Title)) from site_Links

Your query returned 1 rows.

289

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [carfac] Count UNIQUE In reply to
Hi,

This should work;

my $total = $DB->table('Links')->count ( ['DISTINCT(Field_Name)'] );

(fuzzy was right, but just in a different context, but the above is my personal preference for doing this kinda thing <G>).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Aug 8, 2005, 1:20 AM
Quote Reply
Re: [Andy] Count UNIQUE In reply to
Nothing wrong with a little variety, Andy. Cool The built-in count() function is probably better to use in this case since only one type of result is desired.

It's just a habbit to use select() for anything that would typically go in select statement in standard DBI API.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [Andy] Count UNIQUE In reply to
Sweet! Thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase