SELECT * FROM
(SELECT post.* FROM post ORDER BY post.timestamp DESC) as post
GROUP BY post.topic_id
ORDER BY post.timestamp DESC, post.position
LIMIT 15
當試圖執行上面的查詢時,Phalcon出現以下錯誤。查詢本身在默認的sql上工作正常。PhalconPHP無法解析我的查詢
Syntax error, unexpected token (, near to ' SELECT post.* FROM post ORDER BY post.timestamp DESC) as post GROUP BY post.topic_id ORDER BY post.timestamp DESC, post.position LIMIT 15', when parsing: SELECT * FROM (SELECT post.* FROM post ORDER BY post.timestamp DESC) as post GROUP BY post.topic_id ORDER BY post.timestamp DESC, post.position LIMIT 15 (162)
使用下面的PHP碼(用於測試):
$sql = <<< QUERY
*query*
QUERY;
$query = $this->modelsManager->createQuery($sql);
$result = $query->execute();
感謝您的任何幫助。
使用子查詢將無法很好地執行。看看[這篇文章選擇每組一行](http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in- SQL /)。 –
我來看看。謝謝! – tomew