Why is this i am getting error in my Model in codeigniter where it says :
A Database Error Occured
Error Number: 1064
You have error in your SQL syntax;
when i tried run it in mysql it works fine. But when i put it in the model of my CI it gives me Error Number: 1064
Here is my full model code:
public function checkupID() {
$query = $this->db->query(' SELECT check_up_id FROM tbl_check_up JOIN (SELECT MAX(CAST(SUBSTRING_INDEX(check_up_id, '-', -1) AS DECIMAL)) AS max_right FROM tbl_check_up) AS x
ON SUBSTRING_INDEX(check_up_id, '-', -1) = max_right ');
return $query->result();
}
my table structure
+-------------+----------+---------+--------+
| Field | Type | NULL | Key |
+-------------+----------+---------+--------+
| check_up_id | varchar | NO | PRI |
+-------------+----------+---------+--------+
| note | varchar | YES | |
+-------------+----------+---------+--------+
x.max_rightat the end instead ofmax_righttbl_check_up?