--- url84t <[EMAIL PROTECTED]> wrote: > Does anyone know of a way to request letters before numbers in a sql > query so that the following will happen: > > Current results: > > 1 > 2 > 3 > P > > desired results: > > P > 1 > 2 > 3 > > > I know it can be done by pulling the data and reorganizing it using > PHP, but I was hoping there is some way to pull that order from the > database prior to giving the list to php for display. (using mySQL > and php) > > > Thanks, > > Nate
Of course in PHP you could use the usort() function (http://us2.php.net/usort) where you create a custom function to compare values. There are numerous examples on the linked page but be aware that there is also uasort() and uksort() depending on your needs. With MySQL one could use FIND_IN_SET() but I don't think this would work for your case. Here's an example http://lists.evolt.org/archive/Week-of-Mon-20050822/175093.html You could use two queries with a UNION statement: SELECT * FROM table WHERE LEFT(sortfield,1) REGEX '[0-9]' ORDER BY sortfield UNION SELECT * FROM table WHERE !(LEFT(sortfield,1) REGEX '[0-9]') ORDER BY sortfield; I haven't tested the above but it should be pretty close. If your version of MySQL does not support REGEX then look at RLIKE. James Keeline
