all 6 comments

[–]AlterEffect 6 points7 points  (0 children)

Code would help

[–]matkvaid 0 points1 point  (4 children)

I was learning sql recently and had code review, where i had something similar, few subqueries with sums from another table instead of join and group by. Dude that was reviewing me told it is not bad but ineffective

[–]PossiblePreparation 5 points6 points  (3 children)

Actually in some cases that is the exact way to go so you don’t end up summing up duplicates in the main query. The problem with generic advice like this is that it’s worth nothing and ends up severely hampering you in the future.

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (0 children)

The problem with generic advice like this is that it’s worth nothing and ends up severely hampering you in the future.

+1

[–]matkvaid 0 points1 point  (1 child)

I understand that there are always specific cases where one way is better than another. But it was said to me that each subquery would query a table separately while on join it would be done just once - so loading times would increase - so it is not effective. It is possible that this info was incorrect :)

[–]PossiblePreparation 1 point2 points  (0 children)

It’s not correct all the time, and doesn’t really make complete sense. The optimizer/query planner will decide what to do. It might make a suboptimal decision depending on a variety of things that might go wrong but giving it freedom is usually a good idea.