1

I my order by clause I want to do something like

select MyDate
from MyTable
order by case when MyDate is null then 1 else 0 end, MyDate

how can I write

order by case when MyDate is null then 1 else 0 end, MyDate

in Zend I already tried

->order('by case when MyDate is null then 1 else 0 end', 'MyDate')

suggestions?

luca.p.alexandru
  • 1,660
  • 5
  • 23
  • 42

2 Answers2

2

Following what I found on this article, MySQL Orderby a number, Nulls last, this maybe could work for you:

->order(new Zend_Db_Expr("-MyDate DESC"));
Community
  • 1
  • 1
Ernesto Allely
  • 851
  • 10
  • 16
1

Would be nice to provide us with error message or echo $select so we could see where problem is.

Try this:

->order(new Zend_Db_Expr('case when MyDate is null then 1 else 0 end, MyDate'));

Passing Zend_Db_Expr object always puts it in query 'as it is' with no modification.

Volvox
  • 1,639
  • 1
  • 12
  • 10