Reputation: 45
Hi I would like to get unique (distinct) values from database using DBix::Class but can't find how to do it with my current search method:
my $rs = $schema->resultset('DiscreteCalendar')->search(
{
holidaytype => 'W',
branchcode => $branchcode,
},
{
select => [{ DAYOFWEEK => 'date' }],
as => [qw/ weekday /],
where => \['date between ? and ?',$today, $endDate ],
}
);
Thank you for your kind help!
Upvotes: 2
Views: 1234
Reputation: 22294
You should be able to just add distinct => 1
in your second hash to the search
function, e.g.:
my $rs = $schema->resultset('DiscreteCalendar')->search(
{
holidaytype => 'W',
branchcode => $branchcode,
},
{
distinct => 1,
select => [{ DAYOFWEEK => 'date' }],
as => [qw/ weekday /],
where => \['date between ? and ?',$today, $endDate ],
}
);
Upvotes: 3