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,579
  • 4
  • 22
  • 40

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
  • 741
  • 8
  • 14
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,599
  • 1
  • 11
  • 10