How do I flip a column in mysql that has data structured: 'last name, first name'?

Posted by ggg on Stack Overflow See other posts from Stack Overflow or by ggg
Published on 2010-04-16T16:46:45Z Indexed on 2010/04/16 16:53 UTC
Read the original article Hit count: 391

Filed under:
|
|

I want to create a new column in a MYSQL table that has Fn Ln instead of Ln, Fn. Most of my data is printed Fn Ln.

Another idea is to incorporate a string function each time there is an output (php based) but that seems to waste resources. Finally, I couldn't find the syntax (loop or foreach) for my php function anyway.

Here is the working php function that I got from a previous post:

   $name = "Lastname, Firstname";
    $names = explode(", ", $name);
    $name = $names[1] . " " . $names[0];

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql