mysql did not like your query: 'SELECT COUNT(DISTINCT(books.id)) AS cnt FROM books JOIN JOIN book_category ON book_category.bookid = books.id JOIN categories ON book_category.categoryid = categories.id WHERE ( books.published = 1 ) AND ( books.price <= 5.00 OR books.readerSetsPrice = 1 ) AND ( EXISTS (SELECT 1 FROM categories AS node, categories AS parent, categories AS sub_parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt AND ( ( sub_parent.id = 1018 ) ) AND book_category.categoryid = node.id GROUP BY node.id) ) AND ( books.coverImg != '' ) ', err= You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN book_category ON book_category.bookid = books.id JOIN categories ON book_ca' at line 1