Doctrine2 Order By before Group By

2019-04-14 01:11发布

I am having issues implementing a sub-select solution for ORDERING a resulting dataset before the GROUP BY reduces it.

Normally, in SQL you would do a sub-select:

SELECT * FROM (
    SELECT * FROM a_table order by a_table.timestamp desc
) as table_tmp
group by userId

However, I am having difficulty implementing this in DQL. Can anyone point me in the right direction please?

My query is more complex than this and I assume I JOIN other tables through 'table_tmp' and in the outer SELECT.

Thanks.

1条回答
爷的心禁止访问
2楼-- · 2019-04-14 01:23

I'm afraid DQL isn't able to handle such a complex query. However Doctrine allows you to write a custom SQL query and map its results into objects.

Read more about native queries on Doctrine's documentation pages.

查看更多
登录 后发表回答