|
|
|
|
|
by mtts
1163 days ago
|
|
The common solution in this case is simply to also GROUP BY owner.name. That said, if owner.name has different values and you didn’t actually care which one you’d get ANY_VALUE could maybe be useful. Though in that case you could also just use MIN or MAX, which already exist. |
|
I think all optimizers are smart enough already, as this is a super common pattern. I honestly would have preferred this logic to be made more explicit: if you group by the primary key (or by the table name, as someone suggested), you can use all columns from the table without aggregate functions.
This kinda breaks down when you introduce subqueries and CTEs, which is where myopic optimizers can screw the pooch as well, so any_value can be of use there.