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 ') AND cat_subcat = '107' ORDER BY RAND()' at line 1 error: SELECT * FROM tb_cat_categorias WHERE agc in (0,) AND cat_subcat = '107' ORDER BY RAND()