This is Native SQL Query, thats work in MySql:
SELECT a.pshdQty
FROM production_stock_header a
INNER JOIN (SELECT MAX(pshdId) AS pshdId
FROM production_stock_header
WHERE pshdAuditDelete = 'N'
) b
ON a.pshdId = b.pshdId
But, why in Phalcon this always errors?
$triggerSet = $this->modelsManager->executeQuery("
SELECT pshdQty
FROM ProductionStockHeader
INNER JOIN (SELECT MAX(pshdId) AS pshdId
FROM ProductionStockHeader
WHERE ProductionStockHeader.AuditDelete = 'N'
) AS b
ON ProductionStockHeader.pshdId = b.pshdId
");