I have MySQL database that has a table with book data in it. One of the columns in the table is called \"title\". Some of the titles begin the word \"the\" and some do not.<
SELECT Title
FROM book
ORDER BY IF(Title LIKE "The %", substr(Title, 5), Title);
We use the IF
function to strip the "The" (if present) from the beginning of the string before returning the string to the ORDER BY
clause. For more complex alphabetization rules we could create a user-defined function and place that in the ORDER BY
clause instead. Then you would have ...ORDER BY MyFunction(Title)
.