SEVIZ Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158056-reverse-order-of-items-in-a-row/ Share on other sites More sharing options...
Ken2k7 Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158056-reverse-order-of-items-in-a-row/#findComment-833793 Share on other sites More sharing options...
SEVIZ Posted May 14, 2009 Author Share Posted May 14, 2009 Ok fine. New question: How do I split up over 200 current rows of first and last names into two rows? Quote Link to comment https://forums.phpfreaks.com/topic/158056-reverse-order-of-items-in-a-row/#findComment-833806 Share on other sites More sharing options...
Ken2k7 Posted May 14, 2009 Share Posted May 14, 2009 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. =) Quote Link to comment https://forums.phpfreaks.com/topic/158056-reverse-order-of-items-in-a-row/#findComment-833811 Share on other sites More sharing options...
fenway Posted May 14, 2009 Share Posted May 14, 2009 You'd have to make sure you handled the boundary cases, where there was more than a single space in the field. Quote Link to comment https://forums.phpfreaks.com/topic/158056-reverse-order-of-items-in-a-row/#findComment-834344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.