hey all! I'm developing a CGI app for access to a mysql table. I want
to offer users the ability to arbitrarily sort the results. That is,
given the following table:
letter
-----
A
B
C
I want to sort the results as B,C,A , C,A,B, and such. I need to do
this from a single select statement so I can use the LIMIT parameter
to keep state and page through the results.
The best solution I've come up with so far is to dynamically build an
IF statement like the following. Assume the requested order is C, A, B
SELECT letter, IF(letter='C',1,IF(letter='A',2,IF(letter='B',3,4)))
as MYORDER FROM alpha ORDER BY MYORDER
This works, but it seems a tad clumsy. Also, the real table and sort
order uses and combines multiple columns, so it gets really hairy.
How to use formulas to affect sort order in the ORDER BY clause isn't
clear to me (other than RAND()), so I'm wondering if a cleaner
solution lies there.
Any thoughts would be appreciated
Peace,
Michael Todd
---------------------------------------------------------------------
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