私は3つのテーブルを結合し、group byを適用して各タイプの単一の別個の行を選択します。私はテーブルmarketing_followに参加するときに私は複数のエントリがあり、1つを選択する私はグループを使用しています。私はフォローアップテーブルで最新の日付のエントリを選びたいと思っています。私は今、本当にあなたがdesc
ために、日付フィールドをソートする必要があるいくつかの助けjoinとgroupを使用して作成されたテーブルの中で最も最近の日付の行を選択
public function getRegionWiseUserDetails($array){
$this->db->select('mg.region_name, mu.contact_person, mu.contact_number, mu.status, mu.company_name, mu.user_type, mf.follow_up_date, mf.date, mu.user_id');
$this->db->from('marketing_users as mu');
$this->db->join('marketing_group as mg','mg.id = mu.region_id','left');
$this->db->join('marketing_follow_up as mf','mf.user_id_fk =
mu.user_id','left');
foreach($array as $condition){
$this->db->or_where('mg.id',$condition);
}
$this->db->order_by('mf.follow_up_date','asc');
$this->db->group_by('mf.user_id_fk');
$query = $this->db->get();
return $query->result_array();
}
'ます$ this-> DB-> ORDER_BY( 'mf.follow_up_date'、 'DESC')を受け入れる二PARAMTERとしてそれを渡すために持っていけませんこの –
すべてのデータを表示するためにデータテーブルを使用していますか?そうでなければ動作するはずですから。 –
私は生のクエリを書くことができますが、あなた(または他の人)は、それをこのフレームワークにどのように翻訳するかを理解する必要があります。それが解決策であれば、https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very- simple-sql-query – Strawberry