我有这样的表
name|subjects|location
......................
BUET|CSE|Dhaka
BUET|EEE|Dhaka
RUET|CE |Rajshahi
RU |CE |Rajshahi
在这里,所有行都是不同的。如果我使用
$this->db->select('*') and $this->db->distinct()
它会选择 BUET 的所有行,但我只想这样
name|subjects|location
......................
BUET|CSE|Dhaka
RUET|CE |Rajshahi
RU |CE |Rajshahi
这意味着只有第一列必须是不同的,并像往常一样选择所有列。如果我使用 $this->db->select('name'( 和 $this->db->distinct()
.那么其他列会怎样呢?
由于我的原始表有很多列,所以我想使用 $this->db->select('*')
.我认为$this->db->distinct()
不接受任何列作为参数。它根据选择来区分结果。我该怎么做?
像这样尝试
$this->db->select('DISTINCT `name`'); //You may use $this->db->distinct('name');
$this->db->select('*');
按名称选择非重复值。而你的选择拼写错误,可能是打字错误。你也可以使用GROUP BY喜欢
$this->db->select('*');
$this->db->group_by('name');
$this->db->select('*');
$this->db->group_by('column_name');
$this->db->from('tbl_name');
$query = $this->db->get();
return $query->result();
试试这个
你应该用group_by代替区别。
因为 distinct 将返回唯一的行。 但是要逐行具有唯一性,您应该进行分组依据。
希望这有帮助。
$this->db->select('column names');
$this->db->distinct();
$query = $this->db->get('table name');
$query->result();
$this->db->select('job,id');
$this->db->group_by('job');
$query= $this->db->get('technicals')->result_array();
if(!empty($query)){
return $query;
}else{
return false;
}