E
E
eldar_web2015-03-18 11:16:06
MySQL
eldar_web, 2015-03-18 11:16:06

How to sort alphabetically the data (in the presence of quotes)?

There is data in the MySQL database.
I want to sort alphabetically (name ASC). But those entries that have quotes at the beginning and at the end ("Expo"), they are sorted first, and should be sorted by the first letter.
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Entelis, 2015-03-18
@DmitriyEntelis

Please note that IceJOKER and Mikhail Toderashko 's solution will work VERY slowly on even a relatively small base.
This sort does not use indexes.
With each request, for each row, the value of the TRIM function will be calculated, and then also sorted.
The correct solution in my opinion is to update the name field so that there are no quotes in it.
If this is not possible, create a new field without quotes and sort by it.

I
IceJOKER, 2015-03-18
@IceJOKER

ORDER BY TRIM(BOTH '"' FROM name);
stackoverflow.com/questions/1439965/sort-by-name-b...

N
NO, 2015-03-18
@Mihail9575

Try:

SELECT * FROM `table` ORDER BY TRIM(BOTH '"' FROM `name`)

V
Vapaamies, 2015-03-18
@vapaamies

You need to use linguistic sorting. If you can do something like alter session set NLS_SORT = LINGUISTIC in MySQL, as in another Oracle database, this should be the solution. I suggest reading the MySQL documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question