Unix Technical Forum

Order By and Ignore Punctuation

This is a discussion on Order By and Ignore Punctuation within the MySQL General forum forums, part of the MySQL category; --> I would like to perform a query of a personnel database with an ORDER BY clause that ignores punctuation. ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:19 AM
Bill Guion
 
Posts: n/a
Default Order By and Ignore Punctuation

I would like to perform a query of a personnel database with an ORDER
BY clause that ignores punctuation. For example, O'shea would sort
after Osbourne, not to the beginning of the Os.

Is this doable in the query?

-----===== Bill =====-----
--

You can tell a lot about a man by the way he handles these three
things: a rainy day, lost luggage, and tangled Christmas tree lights.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:19 AM
Baron Schwartz
 
Posts: n/a
Default Re: Order By and Ignore Punctuation

Hi,

Bill Guion wrote:
> I would like to perform a query of a personnel database with an ORDER BY
> clause that ignores punctuation. For example, O'shea would sort after
> Osbourne, not to the beginning of the Os.
>
> Is this doable in the query?


If you only have a limited number of punctuation characters to remove, you could
do something like

ORDER BY REPLACE(last_name, "'", "")

You can nest REPLACE() as many times as needed. This is admittedly ugly and
will defeat indexes, but it's the only thing I can think of.

If the sorting must be efficient, you might consider maintaining another column
on the table, which has the name without punctuation. You could then index this
column and ORDER BY it without using any string manipulation.

Baron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com