Hi all, Using mysqld (mysql Ver 12.22 Distrib 4.0.18, for pc-linux (i686)) and have come across some funky SQL code that appears to work occassionally - maybe, depending on the sql client I'm using, but I'm not sure why/not.
I'm using mysql from the command line client, as well as a jdbc client (Netbeans), and MySQL Control Center Center client. I read you can use 'order by null' if you don't want MySQL to do its default ordering of 'group by' results, but this 'order by if( <some_condition>, scalar1, scalar2 )' stuff doesn't seem correct to me. I understand that the following works, and it makes sense to me: mysql> select fname, lname -> from employee -> order by 2; Works. This will order by the 2nd column, lname. Great. But should the following work? I would think not, and it doesn't seem to, but not everyone is convinced: mysql> select fname, lname -> from employee -> order by if(fname is not null, 1, 2); Works. Well, it executes, but it does not order by the first or second column, just the natural order of the table it seems. One added feature is that our 'order by if' function looks like this: -> order by if(fname is null, 0, 1); Doing an 'order by 0' produces an error when not inside an 'if' function, but inside, it seems to be effectively ignored. I'm a bit confused right now on what the behavior of this thing is, but it *seems* to me like this function is *not* working at all - that is, the use of the if(whatever_you_want,blah,blah)' seems to have no effect whatsoever on the ordering of the query results. Can someone shed some light? Thanks. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]