confused by mysql command:select * ..order by if(death is null,0,1),death;
"lanxiazhi" <[email protected]>
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <[email protected]> |
i am learning mysql command to retrieve information from a table.and i want to sort the result.i have a table named president,contains fields like:first_name,last_name,death(which can be null to indicate the president is still alive or a death-date ),so i use : select first_name,last_name,death from president order by if(death is null,0,1),death desc; the result is like(of the death field): null null null 2004-06-05 1994-04-22 ... ... the result confused me. since it's ordered by two fields at the same time:one field can be 0 or 1,the other is a date field,so things is much like the following: 0,null 0,null 0,null 1,2004-06-05 1,1994-04-22 ... but it's by desc order ,i think the result should be: [1,]2004-06-05 [1,]1994-04-22 [0,]null [0,]null [0,]null but it not .who can tell me why? lanxiazhi 2006-08-03