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 gasoleo_a>0 GROUP BY ideess ORDER ' at line 4 SELECT * FROM alonsoftware.gasolina INNER JOIN alonsoftware.gasolinera AS g USING (ideess) WHERE 1 AND DATE(fecha_hora)='2025-01-19' AND ideess IN () AND gasoleo_a>0 GROUP BY ideess ORDER BY gasoleo_a ASC LIMIT 3