Split value from one field to two

前端 未结 14 2153
面向向阳花
面向向阳花 2020-11-22 03:49

I\'ve got a table field membername which contains both the last name and the first name of users. Is it possible to split those into 2 fields memberfirst<

14条回答
  •  -上瘾入骨i
    2020-11-22 04:19

    It seems that existing responses are over complicated or not a strict answer to the particular question.

    I think, the simple answer is the following query:

    SELECT
        SUBSTRING_INDEX(`membername`, ' ', 1) AS `memberfirst`,
        SUBSTRING_INDEX(`membername`, ' ', -1) AS `memberlast`
    ;
    

    I think it is not necessary to deal with more-than-two-word names in this particular situation. If you want to do it properly, splitting can be very hard or even impossible in some cases:

    • Johann Sebastian Bach
    • Johann Wolfgang von Goethe
    • Edgar Allan Poe
    • Jakob Ludwig Felix Mendelssohn-Bartholdy
    • Petőfi Sándor
    • 黒澤

    In a properly designed database, human names should be stored both in parts and in whole. This is not always possible, of course.

提交回复
热议问题