SELECT posttagjoin.ptjpostid, postfields.pfid, postfields.pfcatfieldid, postfields.pfsort, postfields.pftext, postfields.pfvarchar, postfields.pfdate, postfields.pfinteger, postfields.pffloat, postfields.pftime FROM posttagjoin JOIN postfields ON posttagjoin.ptjpostid = postfields.pfpostid JOIN categoryfields ON postfields.pfcatfieldid = categoryfields.catfieldid WHERE posttagjoin.ptjtagid = ? AND categoryfields.catfieldusesort = 1 AND postfields.pfpostid = ORDER BY pfdate DESC LIMIT 1

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 'ORDER BY pfdate DESC LIMIT 1' at line 1