Invalid query: 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 'WHERE (tipo = 'chacao') AND (fondos > 0) AND nmr NOT IN ('' at line 1 Whole query: Select `wa`,`twitter`,`instagram`,`post_instagram`,`facebook`,`linkedin`,`email_cliente`,`ciclo`,`fondos`,`urle`,`tipodemedio`,`tema`,`impresiones`/(DATEDIFF(curdate(),`fecha`)+1) as popularidad,`impresiones`,(`impresiones`/(`fondos`+1)) as pactual,`resumen`,`titulo`,`url`,`texto`,`imagen`, `publicidad`,`nmr`,`idioma` from `publicidades` where (`tipo`='sanjuan' ) and (`fondos`> 0 ) and not nmr in('.0.') order by `ciclo`,fondos desc,`popularidad` LIMIT 0 , 20