i have a table like this
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()
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
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??
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?
Try like this
$this->db->select('DISTINCT `name`'); //You may use $this->db->distinct('name');
$this->db->select('*');
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With