Sort by "last name" in MySQL when the "full name" has periods in it

I found this excellent little conditional order that sorts strings like "First Last" nicely, even correctly handling "First Van Damn".

"SUBSTRING(p.name, LOCATE(' ', p.name) +1)

Now I have names like "Alfred E. Newman" and want the sorting to work correctly for that name (that is, it does not end under E).

Any help would be greatly appreciated.

+5
source share
2 answers

If you really want to do this, how about

RIGHT(p.name, LOCATE(' ', REVERSE(p.name)) - 1)
+9
source

, . , , P, N?

- , . , : ( ) : FirstName, MiddleInitial, LastName.

-1

All Articles