Basically I have a PHP MYSQL query which returns 16 items. 15 of them start with letters A-Z, and one starts with a number (the name of a product is “3d Star Gazer”). In a regular query, sorting alphabetically displays this one item that starts numerically first. I want the list to be sorted alphabetically, with the 3d Star Gazer displayed last.
Is this possible?
SELECT t1.id, t2.name, t2.manufacturer
FROM db.t1
LEFT JOIN db.t2 ON t1.id = t2.id
WHERE year = '2011'
ORDER BY t2.name ASC
I saw this link: Sort MySQL results alphabetically, but with numbers last but the solution wasn’t working for me…
As a secondary question, is it possible to not include the word “The” in the sort? For example, a game is called “The Guessing Game,” I want it to appear sorted as “G”, not as “T”.
Using the IF() operator and adding two columns to control the sort order:
The underscore in the pattern for the LIKE operator matches any single character, and is used to make sure that the returned substring will not be null.
If you don’t want the extra columns in your final output, wrap the above select statement inside another: