Есть такой запрос:
SELECT Messages.*
FROM (
SELECT MAX(id) AS 'maxid', IF (author = 'Gildars', recipient, author) AS 'user'
FROM Messages
WHERE author = 'Gildars' or recipient = 'Gildars'
GROUP BY user
) AS a
INNER JOIN Messages ON a.maxid = id
ORDER BY id DESC
Мне нужно этот запрос выполнить используя PHQL.
Вот как я пытался его выполнить:
$this->modelsManager->executeQuery("SELECT Aincrad\Models\Messages.*
FROM (
SELECT MAX(id) AS 'maxid', IF (author = 'Gildars', recipient, author) AS 'user'
FROM Aincrad\Models\Messages
WHERE author = 'Gildars' or recipient = 'Gildars'
GROUP BY user
) AS a
INNER JOIN Aincrad\Models\Messages ON a.maxid = id
ORDER BY id DESC
");
Но все глухо.
Ошибка
Syntax error, unexpected token (, near to ' SELECT MAX(id) AS 'maxid', IF (author = 'Gildars', recipient, author) AS 'user' FROM Aincrad\Models\Messages WHERE author = 'Gildars' or recipient = 'Gildars' GROUP BY user ) AS a INNER JOIN Aincrad\Models\Messages ON a.maxid = id ORDER BY id DESC ', when parsing: SELECT Aincrad\Models\Messages.* FROM ( SELECT MAX(id) AS 'maxid', IF (author = 'Gildars', recipient, author) AS 'user' FROM Aincrad\Models\Messages WHERE author = 'Gildars' or recipient = 'Gildars' GROUP BY user ) AS a INNER JOIN Aincrad\Models\Messages ON a.maxid = id ORDER BY id DESC (314)