[Dbix-class] Re: [DBIx::Class] using count/distinct

Daniel McBrearty danielmcbrearty at gmail.com
Mon Jan 8 20:21:20 GMT 2007


for any sql dummies like me that come this way in future, this was the answer:

my $t = $c->model('Schema')->resultset('Phrases')->
          count( { language_id => 3},
                     { group_by => 'orig_id'} );

which works like this sql query :

select count (distinct orig_id) from phrases where (language_id = 3);

D


On 1/5/07, Daniel McBrearty <danielmcbrearty at gmail.com> wrote:
> I'm reading the POD at
>
> http://search.cpan.org/~bricas/DBIx-Class-0.07003/lib/DBIx/Class/ResultSet.pm#count
>
> but not really getting it, or whether it's what I want to solve this
> particluar case.
>
> I have a table :
>
> Phrases
>
> id INT PK
> orig_id REFERENCES id
> languuage_id REFERENCES languages.id
>
> Now what I want to do is count the number of phrases in the table that
> have a given language, but for which the orig_id is distinct.
>
> How would I write such a query in DBIx ?
>
> Thanks
>
> Daniel
>
>
>
> --
> Daniel McBrearty
> email : danielmcbrearty at gmail.com
> www.engoi.com : the multi - language vocab trainer
> BTW : 0873928131
>


-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131



More information about the Dbix-class mailing list