d_php Posted October 26, 2021 Share Posted October 26, 2021 I am trying to sort the subquery (joined table) result by using order by id DESC. I am unable to implement this. I used the following query to sort Table2 in DESC order by id, which is not correct. $result = $this->Table->find('all', ['contain' => ['Table2' => ['order' => ['id' => 'desc']]]])->where(['col1' => $col1, 'col2' => $col2])->order(["col3" => 'desc'])->toArray(); Is there any other way available? Quote Link to comment https://forums.phpfreaks.com/topic/314116-sort-subtable-query-result-cakephp-4/ Share on other sites More sharing options...
Barand Posted October 26, 2021 Share Posted October 26, 2021 (edited) What is the actual SQL query that is generated by those incantations? PS What RDBMS are you using? Edited October 26, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/314116-sort-subtable-query-result-cakephp-4/#findComment-1591433 Share on other sites More sharing options...
ginerjm Posted October 26, 2021 Share Posted October 26, 2021 Not sure I have the full picture from your posted text, but I certainly don't know what your query is supposed to look like. From your text, your reference to a 'sub-query' might mean one of the tables in your total query which is joined to the main table and that you want that one table 'sorted'. Why? It is not the result. It is only a source of data that will comprise the final result and THAT can already be sorted. So - what is the real problem? Quote Link to comment https://forums.phpfreaks.com/topic/314116-sort-subtable-query-result-cakephp-4/#findComment-1591435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.