Note that there are some explanatory texts on larger screens.

plurals
  1. PODISTINCT is not working in join query Cakephp
    primarykey
    data
    text
    <p>i am working on a Cakephp 2.x i am newbie to cakephp and getting a very hard time to grasp the cake query methods i have implemented a join query but the distinct is not working here is my code </p> <p>what actually i am trying to accomplish :</p> <p>i have a table name <strong>Messages</strong> in which there are duplicate numbers in field <strong>Message.mobileNo</strong> ... i just want to pick the distinct numbers and then on the bases of those distinct numbers i am comparing or joining the <strong>contacts</strong> table in which there are mobileNo,workNo etc fields and checking that wether those numbers are in the contacts table or not .. if they are grab the contact name for me ..hope you understand it</p> <p>so what i did is ... i am trying to get the rows of <strong>contacts</strong> table against the distnct numbers of Messages table.. </p> <pre><code>function getRecentMessages($userid){ $this-&gt;bindModel(array( 'belongsTo' =&gt; array( 'Contact' =&gt; array( 'className' =&gt; 'Contact', 'foreignKey' =&gt; false, 'conditions' =&gt; array( 'AND' =&gt; array( array('OR' =&gt; array( array('Message.mobileNo = Contact.mobileNo'), array('Message.mobileNo = Contact.workNo'), array('Message.mobileNo = Contact.homeNo'), array('Message.mobileNo = Contact.other'), )), ) ), 'type' =&gt; 'LEFT', 'order'=&gt;'Message.idTextMessage DESC', ) ) ), false); return $this-&gt;find('all', array('conditions' =&gt; array('Message.User_id' =&gt; $userid), 'contain' =&gt; array('Contact' ), 'fields' =&gt; array(' DISTINCT Message.mobileNo',//distnct not working 'Contact.mobileNo', 'Contact.workNo', 'Contact.homeNo', 'Contact.other', 'Contact.name', 'Message.dateTime', 'Message.type', 'Message.body'), 'limit' =&gt; 6)); } </code></pre> <p>i have tried this </p> <pre><code>DISTINCT (Message.mobileNo) as mobileNo </code></pre> <p>but didnt work too </p> <p>i have tried </p> <pre><code> 'group' =&gt; 'Message.mobileNo', </code></pre> <p>by using this it works but then the query is not getting the required results .. i mean the DESC condition not works then</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload