[TriLUG] SQL-fu help request

Igor Partola via TriLUG trilug at trilug.org
Mon Feb 23 15:30:04 EST 2015


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