Welcome Guest, Not a member yet? Register   Sign In
Query Builder Order By
#1

I'm trying to delete the oldest X number of records within my MYSQL database. But it appears that the query builder is not including the order_by into the query.

Code:
$this->db->from($table);
$this->db->where($where);
$this->db->order_by('last_changed', 'ASC');
$this->db->limit(1);
$this->db->delete();

log_message('ERROR', $this->db->last_query());

This is the query from 'last_query'

DELETE FROM `store_page_data`
WHERE `store_page_id` = '123'
AND `type` = 'DRAFT'
AND `client_id` = '1' LIMIT 1

If I run the query manually with order by, it works.

DELETE FROM `store_page_data` WHERE `store_page_id` = '123' AND `type` = 'DRAFT' AND `client_id` = '1' ORDER BY `last_changed` ASC LIMIT 1


I've check the documentation from the query builder and I can't see a reason why it's not being included. 

Any Ideas? 
Reply


Messages In This Thread
Query Builder Order By - by adampwe - 05-26-2019, 04:30 AM
RE: Query Builder Order By - by php_rocs - 05-26-2019, 09:16 AM
RE: Query Builder Order By - by dave friend - 05-26-2019, 09:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB