Jump to content

Sort subtable query result - Cakephp 4


d_php

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.