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.id IN (SELECT bookid FROM format_permissions WHERE enabled = 1 AND formatid IN (4)) 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