I have following query in CodeIgniter:
$this->db
->select($this->vehicle_table.'.idvehicle, mark, type')
->group_by('mark')
->order_by('vehicles.mark', "desc")
->get($this->vehicle_table)
->result_array();
In my table I have record like:
type: auto mark: VW
and
type: bus mark: VW
This query works fine, but I'm getting only record (for VW) where type:auto, this query is ignoring type: bus
I have to "group by" two columns, right?
How should I write query to reach records separately by type and mark ?
edit
Solved, i added "->group_by('type')" before "->group_by('mark')".
Sory for that question, it was easy :)
Yes, you need to group by two columns.
In CI's Active Records, you just make it an array:
...
->group_by(array('mark', 'type'))
...
This will produce: GROUP BY mark, type
See the docs here: http://ellislab.com/codeigniter/user-guide/database/active_record.html