Re: Re: Help! With MySQL CASE problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Darby wrote:
Good people of php-db, I think I have this solved.  For those keeping
score, repeating the CASE condition in the ORDER BY seems to work,
i.e.,

SELECT DISTINCT e.exhibition_id, e.title, e.begin_date,
CASE 'heading'
WHEN UNIX_TIMESTAMP( ) >= e.begin_date
THEN 'Coming Up'
ELSE 'Now Showing'
END 'heading',
e.end_date, special
FROM exhibition e
WHERE e.end_date >= UNIX_TIMESTAMP( )
ORDER BY
CASE
WHEN UNIX_TIMESTAMP( ) >= e.begin_date
THEN 'Coming Up'
ELSE 'Now Showing'
END , e.begin_date ASC

I don't know why, however.

I think that's an sql standard thing.. because the "heading" column is being made up (by the case statement) you can't use the alias in an order by or group by.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux