Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by, ignore articles

Status
Not open for further replies.

troncale

Programmer
Nov 15, 2002
1
US
I would like to request help using the 'order by' function. Is there a mechanism in MySQL that makes 'order by' ignore articles (An, The, A) and sort on the first letter of the next word?

My SELECT statement would look something like this:

"SELECT title FROM book_table WHERE subject = 'Anthropology' ORDER BY title;

As it is, the title "The Arts of Anatolia" would come after the title "Greek Pottery". I was wondering how to allow Mysql to ignore the "The".

Thanks for your help!

James
 
SELECT
title,
CASE
WHEN (LEFT(title, 4) = 'The ') THEN TRIM(LEADING 'The ' FROM title)
WHEN (LEFT(title, 3) = 'An ') THEN TRIM(LEADING 'An ' FROM title)
WHEN (LEFT(title, 2) = 'A ') THEN TRIM(LEADING 'A ' FROM title)
ELSE title
END AS ordercolumn
FROM book_table
ORDER BY ordercolumn

hope this works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top