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 published_at IS NOT NULL
AND (
' at line 7
SELECT * FROM postagem
WHERE
id = (
SELECT max(id) FROM postagem
WHERE
id <
AND published_at IS NOT NULL
AND (
texto IS NOT NULL
OR texto != ''
)
AND categoria_id =
)