Welcome Guest, Not a member yet? Register   Sign In
Suggestion: Order by is null condition
#1

I am using CI 4.2.1 on my project

I needed to use ORDER BY IS NULL ASC/DESC on a datetime from my db.
How about to add the possibility to add a conditional order by is null?

CodeIgniter\Database\BaseBuilder (line 1422)
Previously
$direction = in_array($direction, ['ASC', 'DESC'], true) ? ' ' . $direction : '';


In
$direction = in_array($direction, ['ASC', 'DESC', 'IS NULL ASC', 'IS NULL DESC'], true) ? ' ' . $direction : '';
Reply
#2

try like this orderBy('IS NULL', 'ASC', false);
Reply
#3

Hi,
If you are using MySQL NULL values are considered having a lower value than any none NULL value, so order by "fieldName" ASC will give you NULL values first.
And The opposite order by "fieldName" DESC will put the NULL values last.
Regards
A good decision is based on knowledge and not on numbers. - Plato

Reply




Theme © iAndrew 2016 - Forum software by © MyBB