MySQL sort by name

Is it possible to sort the column in alphabetical order, but ignoring some words, for example, 'The'

eg.

A normal request will return

string 1
string 3
string 4
the string 2

I would like to return

string 1
the string 2
string 3
string 4

Is it possible?

EDIT Please note that I want to replace a few words, such as A, A, etc. Can this be done?

+3
source share
4 answers

You can try

SELECT id, text FROM table ORDER BY TRIM(REPLACE(LOWER(text), 'the ', ''))

but note that for large datasets it will be very slow, since it has to recount a new row for each row.

IMO you are better off with a separate column with an index on it.

For multiple stopcodes, just keep nested calls REPLACE. :)

+5

, ORDER-:

SELECT * FROM yourTable ORDER BY REPLACE(yourField, "the ", "")
0

"The"

SELECT  *
FROM    YourTable 
ORDER BY REPLACE(Val,'The ', '')
0

, 75 000 , . PHP script, , "A", "An" "The" . . .

, , . .

0

Source: https://habr.com/ru/post/1724099/


All Articles