Last active
July 24, 2019 09:56
-
-
Save felixpenrose/e4cc45100afbfa1437a7b3777bae518e to your computer and use it in GitHub Desktop.
Split up full name field into first (inc middle) names and last name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE tbl t1, | |
( | |
SELECT | |
id, | |
TRIM(SUBSTRING(name, 1, LENGTH(name) - LENGTH(SUBSTRING_INDEX(name, ' ', -1)))) AS first_name, | |
SUBSTRING_INDEX(name, ' ', -1) AS last_name | |
FROM reviews | |
WHERE first_name IS NULL | |
) t2 | |
SET t1.first_name = t2.first_name, | |
t1.last_name = t2.last_name | |
WHERE t1.id = t2.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment