CodeIgniter4
CodeIgniter4 copied to clipboard
ORDER BY is not used on DELETE statements
$sql = "DELETE FROM `table_name` WHERE `feed_id` = " . $feed_id . " ORDER BY `date` ASC LIMIT 25"; // query to be executed
$result = $this->db->table('table_name')
->where('feed_id', $feed_id)
->orderBy('date', 'ASC')
->limit(25)
->delete();
echo $this->db->showLastQuery(); // DELETE FROM `table_name` WHERE `feed_id` = 15 LIMIT 25
orderBy() function is not working when delete() function is used in query builder.
What database driver are your using?
I see that the $QBOrderby
property is never used in any driver so this is not a bug but a missing feature for deletes.
Are you willing to tackle this?
DB layer was ported from CI3 and we supported there a lot more databases. Not every one of them supported ORDER BY with DELETE. That's why we don't have this feature today.
With currently supported databases, it's now doable. Though SQLSRV may be a little tricky.