I use Doctrine 2.4. And I try to order my list of campaign by priority ascending with priority NULL and priority to 0 at the end.
SELECT * FROM campaign ORDER BY priority IS NULL, priority = 0, priority ASC
Have you got an idea how I can do this?
$query->addOrderBy('c.priority', 'ASC');
I found the solution, I did that:
$query->addSelect('CASE WHEN c.priority IS NULL THEN 1 ELSE 0 END as HIDDEN priority_is_null');
$query->addSelect('CASE WHEN c.priority = 0 THEN 1 ELSE 0 END as HIDDEN priority_is_zero');
$query->addOrderBy('priority_is_null', 'ASC');
$query->addOrderBy('priority_is_zero', 'ASC');
$query->addOrderBy('c.priority', 'ASC');
order by case when priority is null then 1 else 0 end, priority
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With