Invalid query: SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=735 LIMIT 0, 2 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=734 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=733 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=732 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=731 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=730 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=729 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=728 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=727 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=726 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=725 UNION ALL SELECT * FROM Materials m INNER JOIN AllDocs ON AllDocs.documentid = m.documentid AND sid=695 WHERE tema=724 ORDER BY 13 DESC : Incorrect usage of UNION and LIMIT