CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

ORDER BY is not used on DELETE statements

Open suresh-credencetech opened this issue 3 years ago • 3 comments

$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.

suresh-credencetech avatar May 25 '21 14:05 suresh-credencetech

What database driver are your using?

paulbalandan avatar May 25 '21 17:05 paulbalandan

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?

paulbalandan avatar May 25 '21 17:05 paulbalandan

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.

michalsn avatar Jun 27 '21 05:06 michalsn