MySQL Sort Alphabetically but Ignore “The”

前端 未结 6 712
一整个雨季
一整个雨季 2020-12-16 18:22

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.<

6条回答
  •  感动是毒
    2020-12-16 19:12

    do a case when to check if the column value starts with the and if it does, return the title without the 'The'. This will be a new column that you will be using later on for the sort order

    select title, case when title like 'The %' then trim(substr(title from 4)) else title end as title2 from tablename order by title2;
    

提交回复
热议问题