Reputation: 287
I have a id column in a table with a costant prefix,for eg. NC1,NC2,NC3.....I have to calculate the maximum id from the id column.Here is how i do it in mysql -
SELECT max(cast(substr(`column_name`,3) as unsigned)) FROM `table_name`
Here is how i tried to do in CodeIgniter
$this->db->select_max('cast(substr('column_name',3) as unsigned'),false));
$result=$this->db->get('table_name');
It just doesn't work,What is wrong with the above code?
Upvotes: 1
Views: 2462
Reputation: 54619
Try it like this:
$this->db->select_max('cast(substr(`column_name`,3) as unsigned)','max_id');
$this->db->get('table_name');
The second parameter is to rename the resulting field
Upvotes: 1