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