0
我在CakePHP的新手,想实现这个查询CakePHP的使用JOIN在find方法
SELECT DISTINCT textmessage.mobileNo FROM textmessage
JOIN contacts
ON textmessage.User_id=contacts.User_id AND textmessage.mobileNo = Contacts.mobileNo
我在这里希望只有一个结果..想在文字信息来实现此查询控制器...我从来没有使用联接查询之前在CakePHP ...我有两个表实际上是一个mobileNo场,我想找回mobileNo如果mobileNo的TextMessage的表也是联系表
这里是我根据我的质量要求修改您的查询..
$this->bindModel(array('belongsTo' => array('Contact' => array('className' => 'Contact',
'foreignKey' => false,
'conditions' => array('Message.user_id = Contact.user_id','Message.mobileNo = Contact.mobileNo')))), true);
return $message_details = $this->find('all', array('conditions' => array(),
'fields' => array('DISTINCT mobileNo')));
@Arjun Jain谢谢Arjun ..但是你没有在你的查询中使用“distinct”? – hellosheikh
以及当我运行你的第一个查询..它不给我所需的结果。 – hellosheikh
我在哪里得到您的查询mobileNo也没有明显的用途? – hellosheikh