从Codeigniter中的列中仅选择唯一值 [英] Select only unique values from a column in codeigniter

查看:82
本文介绍了从Codeigniter中的列中仅选择唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的桌子

name|subjects|location
......................     
BUET|CSE|Dhaka
BUET|EEE|Dhaka
RUET|CE |Rajshahi
RU  |CE |Rajshahi

这里所有行都是不同的.如果我使用

here all the rows are distinct.And if I use

 $this->db->select('*') and $this->db->distinct() 

它将选择BUET的所有行,但我只想要这样

it would select all the rows of BUET but i only want like this

name|subjects|location
......................     
BUET|CSE|Dhaka
RUET|CE |Rajshahi
RU  |CE |Rajshahi

这意味着只有第一列必须是可区分的,并照常选择所有列.如果我使用$ this-> db-> select('name')和$this->db->distinct(),它将起作用.那么其他专栏呢?

That means only the first column must be distinct and select all the columns as usual.And it would work if i use $this->db->select('name') and $this->db->distinct(). Then what would be about the other columns??

由于我的原始表有很多列,因此我想使用$this->db->select('*').我认为$this->db->distinct()不会将任何列作为参数.根据选择区分结果.我怎样才能做到这一点?

As my original table has many columns so I want to use $this->db->select('*'). I think $this->db->distinct() does not take any column as parameter. It differentiate result based on select. How can I do this?

推荐答案

尝试这样

$this->db->select('DISTINCT `name`'); //You may use $this->db->distinct('name');  
$this->db->select('*');

选择按名称的不同的值.您的SELECT拼写错误,可能是键入错误.您也可以使用GROUP BY,例如

Select the distinct values by names.And your SELECT spelt wrong,may be its a typing mistake.And you can also use GROUP BY like

$this->db->select('*');
$this->db->group_by('name');

这篇关于从Codeigniter中的列中仅选择唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆