How to get the first name from customer_name column
P粉908643611
P粉908643611 2024-04-06 17:43:30
0
2
594
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粉908643611
P粉908643611

reply all(2)
P粉884548619

Using SUBSTRING_INDEX()Requires 3 parameters:

  1. Column name
  2. Delimiter
  3. The number of occurrences

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粉276064178

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;

Result set:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template