簡體   English   中英

在codeigniter中使用distinct選擇多列

[英]select multiple columns using distinct in codeigniter

這是model.php

function get_data_wheree($table)
{
    $this->db->select('course_offrd_name','collg_id');
    $this->db->distinct('');

    return $this->db->get('tbl_course_offered')->result();
}

在這里,我想使用多列 course_offrd_name 和 collg_id 使用一列作為 DISTINCT 關鍵字,第二列作為普通選擇。 但我只能選擇 course_offrd_name 而不能打印 collg_id。 如何使用一個不同的和一個正常的選擇打印兩列。 course_offrd_name 作為 DISTINCT 和 collg_id 作為正常選擇我使查詢變得簡單。 如何解決代碼中的問題?

嘗試像這樣使用不同的:

function get_data_wheree($table)
{
    $this->db->distinct('course_offrd_name');
    $this->db->select('collg_id');

    return $this->db->get('tbl_course_offered')->result();
}

或者您也可以使用GROUP BY

function get_data_wheree($table)
{
    $this->db->select('course_offrd_name, collg_id');
    $this->db->group_by('course_offrd_name');

    return $this->db->get('tbl_course_offered')->result();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM