Skip to content

Instantly share code, notes, and snippets.

@baniol
Last active December 17, 2015 03:59
Show Gist options
  • Save baniol/5547473 to your computer and use it in GitHub Desktop.
Save baniol/5547473 to your computer and use it in GitHub Desktop.
mysql split username, string
-- Splits username by first space, shortens first name to the first letter & adds a dot. Ex.: Jonh Smith -> J. Smith
SELECT CONCAT(CONCAT(LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX( `username` , ' ', 2 ),' ',1),1),"",". ") ," ", SUBSTRING_INDEX(SUBSTRING_INDEX( `username` , ' ', -1 ),' ',2)) AS user
FROM tbl_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment