I’m pulling a list of names from a database;
SELECT * FROM people ORDER BY name ASC
However, some of the names are like [Mod]John, and these are all at the end of the list instead of in alphabetical order, because of starting with [.
Is there a simple way to ignore the [mod] part when sorting my names, but still pull the entry? So I still have John in my list?
Do I need to sort them using PHP after pulling?
Advertisement
Answer
Use (please check syntax):
SELECT *, replace(name, '[mod]', '') as sortname FROM people order by sortname ASC
But essentially use the replace function.