简体   繁体   English

在codeigniter中使用distinct选择多列

[英]select multiple columns using distinct in codeigniter

This is model.php这是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();
}

Here I want to use multiple columns course_offrd_name and collg_id using one columns as DISTINCT keywords and second as normal select.在这里,我想使用多列 course_offrd_name 和 collg_id 使用一列作为 DISTINCT 关键字,第二列作为普通选择。 but I'm only able to select course_offrd_name and not able to print collg_id.但我只能选择 course_offrd_name 而不能打印 collg_id。 how to print both the columns with one distinct and one normal select.如何使用一个不同的和一个正常的选择打印两列。 course_offrd_name as DISTINCT and collg_id as normal select I have made the query simple. course_offrd_name 作为 DISTINCT 和 collg_id 作为正常选择我使查询变得简单。 How do I solve the issue in the code?如何解决代码中的问题?

Try to use the distinct like this :尝试像这样使用不同的:

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

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

Or you can also use a GROUP BY :或者您也可以使用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