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 p.siglopal=an.sigloid and an.grupofecha=1 and p.visible=1 order by p.palabra' at line 14
select distinct p.*, an.exportar, ( case when p.annus>0 then p.annus when p.annus2>0 then p.annus2 when length(an.exportar)>0 then an.exportar else '-' end ) as fecha, if(length(t.tipoannus)>0,t.tipoannus,'-') as tipologia from palabras p inner join palsuf ps inner join antiguo_o_neol an inner join epocagrupogeneral egg left join tipoannus t on t.id_tipoannus=p.tipoannus where p.idpal=ps.idpal and p. caracterrel <> 3 and ps.sufid= and p.siglopal=an.sigloid and an.grupofecha=1 and p.visible=1 order by p.palabra