small optimization on category SQL queries
Merge pull request #1598 from conejoninja/sqlcatopt

small optimization on category SQL queries