SELECT c.*, COUNT(i.id) AS count_items FROM gallery_categories c LEFT JOIN gallery_items i ON i.category_id = c.id WHERE c.sub=0 GROUP BY c.id ORDER BY c.id DESC
SQLSTATE[HY000]: General error: 1 no such column: c.sub