Complex mysql ORDER BY

Executing the following query:

SELECT title FROM table ORDER BY title

gives me:

"Hello"
"Zebra"
Apple
Beta
Cactus

How should I ORDER the first alphabetical character to get:

Apple
Beta
Cactus
"Hello"
"Zebra"

?

+5
source share
3 answers

You will need to remove the quotes before sorting the data. You can easily remove them using a function TRIMin MySQL like:

SELECT title 
FROM table 
ORDER BY TRIM(BOTH '"' FROM title);
+6
source
...ORDER BY REPLACE(title, '"', '');
+3
source
SELECT title FROM table ORDER BY TRIM(LEADING '"' FROM title)
+3
source

All Articles