[TriLUG] SQL-fu help request

Matt Flyer via TriLUG trilug at trilug.org
Mon Feb 23 19:06:08 EST 2015


On Monday, February 23, 2015 06:14:56 PM Alan Porter via TriLUG wrote:
>  > I may have to do multiple queries (open, then closed) and some surgery
>  > to join them in to a set, but that might be complicated.
> 
> Repeat after me...
> 
>      You're almost always better off letting database do the sorting
>      and filtering.
(repeating after Alan)
You're almost always better off letting database do the sorting and filtering.
I agree.  I figured that there was a way to get it to do so and I am surprised 
that the solution was so simple.

> Doing it yourself after the query is usually slower, more complicated,
> and prone to error.
Undoubtedly.

> In this case, it sounds like Igor has you taken care of.  Good advice,
> that guy usually has.
Yes, it was very good advice and I learned something as a result.  A lot of my 
mistake was in thinking that the order of the limit and order by clauses was 
order agnostic and that the statements would be applied after the query, not 
impact the query.  The reading I had done was leading me down the 'group by' 
path because that is supposed to be applied early in the query, whereas 'order 
by' is applied later. 


More information about the TriLUG mailing list