1055. Query Error 1055: Expression #2 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'admin_shopru.cp1.sort' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by Query: SELECT p.*,p.id,(p.count > 0 || p.count IS NULL) AS in_stock FROM shop_product p JOIN shop_category_products cp1 ON p.id = cp1.product_id WHERE p.status = 1 AND cp1.category_id IN(66,88,91,98,101,105,107,115,119,124,131) GROUP BY p.id ORDER BY in_stock DESC,cp1.sort ASC, p.id LIMIT 30