Skip to content

Commit

Permalink
Add GROUP BY E.Id to fix mysql complaining about teh aggregate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Connor committed Sep 20, 2023
1 parent 2e17d2e commit 92d3e00
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/ZoneMinder/lib/ZoneMinder/Filter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ sub Sql {
E.*,
unix_timestamp(E.StartDateTime)
AS Time,
CONCAT_WS(", ", (SELECT Name FROM Tags WHERE Id IN (SELECT TagId FROM Events_Tags WHERE EventId=E.Id)))
GROUP_CONCAT(T.Name SEPARATOR ", ")
FROM Events
AS E
LEFT JOIN Events_Tags
AS ET
ON E.Id = ET.EventId
LEFT JOIN Tags
AS T
ON T.Id = ET.TagId
';

if ( $filter_expr->{terms} ) {
Expand Down Expand Up @@ -410,6 +416,7 @@ sub Sql {
} elsif ( $filter_expr->{sort_field} ne '' ) {
$sort_column = 'E.'.$filter_expr->{sort_field};
}
$sql .= ' GROUP BY E.Id ';
if ( $sort_column ne '' ) {
$sql .= ' ORDER BY '.$sort_column.' '.($filter_expr->{sort_asc} ? 'ASC' : 'DESC');
}
Expand Down

0 comments on commit 92d3e00

Please sign in to comment.