Jump to content

Reverse order of items in a row?


SEVIZ

Recommended Posts

I have a row in my table with peoples names.  Right now it is last name first and then first name.  Is there a query I could run to reverse these two words in all the rows?

 

Currently looks like this:

Murphy Peter

Kovac Walter

 

Want it to be:

Peter Murphy

Walter Kovac

 

Thanks for any ideas.

Link to comment
Share on other sites

Well you can use a combination of LOCATE(), LEFT() and RIGHT() MySQL functions, but to me, it's just not a good way of storing data. Why not have 2 columns - one for first name and one for last. Then you wouldn't have this issue.

Link to comment
Share on other sites

Well, you'll still end up using those 3 functions in the SQL unless you plan to do it the heavy way by using PHP. Create 2 columns - one for first name and one for last name. Then use an UPDATE SQL query.

 

Look here on how those 3 functions are used - http://dev.mysql.com/doc/refman/5.1/en/string-functions.html

 

I'm pretty sure a similar case came up using those 3 functions. If you really want and have the time, traverse a few pages in this forum and see if you can find that topic. But it's probably not too hard. Give it a try. =)

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.