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 product_id in(select product_id from yp_product_cat where category_id=) and ' at line 1 : select min(product_id) from yp_product where product_id > and product_id in(select product_id from yp_product_cat where category_id=) and product_status='Active'