If you drop the order by, does the second query work?

Cal
*
* Cal Evans
* Senior Internet Dreamer
* http://www.calevans.com
*
----- Original Message -----
From: "BCC" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 19, 2001 12:18 PM
Subject: IFNULL issues??


> Hi,
>
> Maybe someone could take a moment to explain this behavior?
>
> I am using IFNULL() in an order by statement to push null values to the
> end of a table for sorting.
>
> For example:
> mysql> select distinct s.some_pk as myid, queryid from data_table s,
> userdata.queryinfo q where s.some_pk=q.myid order by IFNULL(myid, 999);
>
> This works fine (let's ignore for the moment the possibility of null
> primary key values :) ).
>
> However, this does not work:
> mysql>  select distinct s.some_pk as myid from data_table s,
> other_data_table where s.some_pk=232 order by IFNULL(myid, 999);
> ERROR 1054: Unknown column 'myid' in 'order clause'
>
> What gives?  What is the difference for IFNULL between these two
> statements?  My first thought was that IFNULL for some reason does not
> recognize
> aliases, but then the first statement works.  Also, 'pkid' is not
> ambiguous.
>
> I don't get it.  Am I missing the obvious?
>
> Anyone?
> Thanks,
> Bryan
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to