Welcome Guest, Not a member yet? Register   Sign In
DISTINCT key word in the db->select
#1

[eluser]Ace_ov_Spade[/eluser]
today I found the error while using DISTINCT keyword in db->select() function. my code is something like:

Code:
$this->db->select('DISTINCT `name`');
$Q = $this->db->get('vehicle',$condition);

I got the error message like:

A Database Error Occurred
Error Number: 1054
Unknown column 'DISTINCT' in 'field list'
SELECT `DISTINCT` `name` FROM (`vehicle`)

my question is: is there anyway to use select distinct field name using db_select() method? or I have to use the db->query() method?
#2

[eluser]tonanbarbarian[/eluser]
you need to tell the select method to not quote the fields
Code:
$this->db->select('DISTINCT `name`', TRUE);
#3

[eluser]Ace_ov_Spade[/eluser]
tonanbarbarian,
thanks for your reply Smile I didn't know about 'TRUE'

I used it like
Code:
$this->db->distinct();
$this->db->select('name');
$Q = $this->db->get('vehicle',$condition);




Theme © iAndrew 2016 - Forum software by © MyBB