tomew
tomew

Reputation: 57

PhalconPHP can not parse my query

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 is throwing following error when trying to execute the query above. The query itself works fine on default sql.

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)

Using the following PHP-Code (for testing):

$sql = <<< QUERY
    *query*
QUERY;

$query = $this->modelsManager->createQuery($sql);
$result = $query->execute();

Thank you for any help.

Upvotes: 1

Views: 104

Answers (1)

num8er
num8er

Reputation: 19372

  1. create view, to keep already reverse sorted virtual table:

    CREATE VIEW v_latest_posts AS SELECT * FROM post ORDER BY timestamp DESC

  2. use view in select:

    SELECT * FROM v_latest_posts GROUP BY topic_id ORDER BY timestamp DESC, position ASC LIMIT 15

Upvotes: 1

Related Questions