SELECT
-- Assumed to be trimmed
name
-- Does name contain multiple words?
,(LOCATE(' ', name) = 0) AS hasMultipleWords
-- Returns the end of the string back until reaches a space.
-- E.g. "John Doe" => "Doe"
-- E.g. "Francis Scott Key" => "Key"
-- E.g. "Prince" => "Prince"
,REVERSE(SUBSTRING_INDEX(REVERSE(name), ' ', 1)) AS lastName
-- Everything not included in the last name.
-- E.g. "John Doe" => "John"
-- E.g. "Francis Scott Key" => "Francis Scott"
-- E.g. "Prince" => ""
,TRIM(SUBSTRING(name, 1, CHAR_LENGTH(name) - CHAR_LENGTH(SUBSTRING_INDEX(REVERSE(name), ' ', 1)))) AS firstNames
FROM `elgg_users_entity`
LIMIT 100