Skip to content

Instantly share code, notes, and snippets.

@felixpenrose
Last active July 24, 2019 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixpenrose/e4cc45100afbfa1437a7b3777bae518e to your computer and use it in GitHub Desktop.
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
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