select substring(custmer_name, 1, instr(custmer_name, ' ')) as first_name from sales.customers;
This solution gave me the answer, but it doesn't work for the last name
P粉8845486192024-04-07 16:34:04
Using SUBSTRING_INDEX()Requires 3 parameters:
You can find more instructions here Article
Inquire
SELECT SUBSTRING_INDEX(customer_name,' ', 1) as first_name, SUBSTRING_INDEX(customer_name,' ', -1) as last_name FROM customer;
P粉2760641782024-04-07 14:24:41
Please test it: I use the locate function to define the location of " ".
SELECT LEFT(customer_name, LOCATE(' ',customer_name)-1) as first_name, RIGHT(customer_name, LENGTH(customer_name)-LOCATE(' ',customer_name)) as last_name FROM customer;