NameSilo

MySQL Question

Spaceship Spaceship
Watch

moondog

Established Member
Impact
23
I ran into a strange thing that I was not expecting today.

I am trying to query from a database table and order by a column. This is not normally a big deal. The column (names "TLD") on which I am sorting is an ENUM and is defined like this:

enum('com', 'net', 'org', 'us', 'info', 'biz')

The select statement I have looks like your garden variety select statement:

$sql = "SELECT * from DOMAINS order by TLD asc";

I expected the results to be given to me in this order:

biz
com
info
net
org
us

This is not the case. The results are displayed in the order that they appear in the enumeration. In other words, they display in this order:

com
net
org
us
info
biz

Other than the obvious solution of putting the values in the enumeration in the correct order - Is there a way to sort the rows in the enumerated column alphabetically instead of the way that they appear in the enumeration?

-Bob
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
then try enum('biz', 'com', 'info', 'net', 'org', 'us')
 
0
•••
0
•••
dongan said:
then try enum('biz', 'com', 'info', 'net', 'org', 'us')
Thats what i said but i cant see my post :s
 
0
•••
sdsinc said:
It's a known issue but interesting as it might happen to us ;)
http://sunsite.mff.cuni.cz/MIRRORS/ftp.mysql.com/doc/en/ENUM.html

Thanks Kate! Guess I need to rethink a little bit.





dongan said:
then try enum('biz', 'com', 'info', 'net', 'org', 'us')

webmonkey said:
Thats what i said but i cant see my post :s

Thanks guys, but my original post said

"Other than the obvious solution of putting the values in the enumeration in the correct order - Is there a way to sort the rows in the enumerated column alphabetically instead of the way that they appear in the enumeration?"

-Bob
 
Last edited:
0
•••
Quick fix:cast the enum value into a regular string

PHP:
$sql = "SELECT * from DOMAINS order by concat(TLD, '' ) asc";
 
0
•••
sdsinc said:
Quick fix:cast the enum value into a regular string

PHP:
$sql = "SELECT * from DOMAINS order by concat(TLD, '' ) asc";


SWEET!

Works perfectly.

-Bob
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back