Darya Balu
Darya Balu

Reputation: 149

MySQL: select surname ONLY from the column with name and surname

I have a column which contains client's name and surname in CUSTOMER table.

11 | John Doe
12 | Kate Sanchez 
13 | Amy Lee

The purpose is to select only id-s and names to be displayed in the column, like:

11 | Doe
12 | Sanchez 
13 | Lee

The length of names varies, so I can't use SUBSTRING.

Upvotes: 0

Views: 409

Answers (1)

GMB
GMB

Reputation: 222432

Do you want substring_index()?

select id, substring_index(name, ' ', -1) last_name
from customer

This selects the part of the string that follows the last space.

Upvotes: 3

Related Questions