[PR] Fix SQL syntax error where LIMIT was used too early