I need to write a query that manipulates a name field from "firstname lastname" to "lastname, firstname". I have read multiple solutions to split firstname and lastname to separate fields, unfortunately I haven't found anyting on manipulating substrings within the same field. Can this be done?
Using substrings function to rearrange name field
Collapse
X
-
This can be done using regular expression's backreferene but MySQL does not support backreferences.
What is the problem implementing 2 columns solution? An alternative can be to use a PHP script to select the value and then update after swaping it. -
Hi, and welcome to TSDN!
As the first rule (1NF) of relational database design says, no field should contain more than one piece of data. So it would not make much sence that a relational database engine would include functions to re-arrange data inside a single field, would it?
This rule exists for a number of reasons, one most likely being to avoid the excact problem you are facing.
So I highly reccomend splitting up the field.
If you, however, feel that you can not split up the field, you will have to make some script to re-arrange and update your fields.Comment
Comment