Jump to content

ORDER BY the SECOND word in a field


scampisi

Recommended Posts

I have a situation where I am needing to sort a list alphabetically by the last name. However, due to BAD planning, all of the names are stored in a single field like this
[i]firstname lastname[/i]
What is going to be my best way to sort my list? I looked through string manipulation in MYSQL, but I couldn't find a way to doa select statment that would search through my table, and pull all names based on the lastname.
SELECT * from catalog ORDER BY . . .
and here I want to say
ORDER BY
"the first character after the first space in " FULLNAME

Any ideas?

Link to comment
Share on other sites

I can't give you a straight answer, but I see that you can use regexp in MySQL... here's just one page I found, but it should be a good starting point....

[a href=\"http://www.tech-recipes.com/mysql_tips484.html\" target=\"_blank\"]one page discussing regular expressions in MySQL selects[/a]

I'd highly recommend exporting the data, and re-importing it into two tables though, because it'll save you time down the road when any similar situations arise.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.