You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(username='dstonek' OR username='zalomol' OR username='nagar') AND WHERE tercera' at line 1SELECT ordinal, foto, fotow, texto_foto_ing, fotos.tercera_clasif, grupo, username, coord_google, votos, puntaje FROM fotos (username='dstonek' OR username='zalomol' OR username='nagar') AND WHERE tercera_clasif = 'PEY' AND seleccion='si' ORDER BY orden_output ASC, fecha DESC, ordinal DESC