[TriLUG] SQL-fu help request

Matt Flyer via TriLUG trilug at trilug.org
Mon Feb 23 15:39:50 EST 2015


Thank you again, Igor.

You are correct and that did the trick! 

My (lack of experience / understanding) was the problem.  I see what you are saying, by my order of ORDER BY and LIMIT, I was forcing it to be backwards, rather then letting it order all the entries.  When I changed those, I got the desired result.

Sent from my iPad

> On Feb 23, 2015, at 3:30 PM, Igor Partola <igor at igorpartola.com> wrote:
> 
> I think your problem comes from using a subquery. SQL makes it easy to do what you are trying to do. Take a look at my original SELECT query: it will do what you need.
> 
> This is so because LIMIT is applied after ORDER BY: basically MySQL will construct a way to return all the items in the correct order, then only return the ones that fit the LIMIT parameter. Your query has different behavior with different pages sizes because you are forcing it to do this backwards: apply the limit, then order it. When you return all results the order is correct, but when you have a page size of 10, you first select 10 entries in arbitrary order, then sort those.
> 
> Igor


More information about the TriLUG mailing list