Invalid query: SELECT c. * , count( g.goods_ccat_id ) AS countg , if (c.parent_id <> 0 , c.parent_id , c.id) as pid FROM biz_custom_catalog c LEFT JOIN biz_goods g ON c.id = g.goods_ccat_id WHERE c.shop_id = AND g.shop_id = GROUP BY g.goods_ccat_id UNION SELECT c. * , 0 AS countg , if (c.parent_id <> 0 , c.parent_id , c.id) as pid FROM biz_custom_catalog c where c.shop_id = and c.id not in (select g.goods_ccat_id from biz_goods g where g.shop_id = AND g.goods_end_active_time >1265689112 group by g.goods_ccat_id) [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 'AND g.shop_id = GROUP BY g.goods_ccat_id UNION SELECT c. * , 0 AS countg , if (' at line 1]