Home > Mobile >  First order by uppercase & lowercase
First order by uppercase & lowercase

Time:02-22

I have a few records which start with lowercase & uppercase.

SELECT * FROM wording ORDER BY word ASC;
Lanza
Mensi
Mhiob
blackbery
umbre
apple
Etios
Iomio

I am trying to order this by A-Z and a-z, something like

Etios
Iomio
Lanza
Mensi
Mhiob
apple
blackberry
umbre

So, all the word which is starting with capital come first and after then all lowercase words.

CodePudding user response:

I think ASCII function might help you -

SELECT * FROM wording
ORDER BY CASE WHEN ASCII(word) BETWEEN 65 AND 90 THEN 1 ELSE 2 END ASC, word DESC;

CodePudding user response:

This should work too:

select * 
from wording 
order by binary(word) ASC;

Result:

word
Etios
Iomio
Lanza
Mensi
Mhiob
apple
blackbery
umbre

enter image description here

Reference Website:SQL Practice

  • Related