By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table names(
name varchar(25));
insert into names values
('Vladimir Putin'),
('Boris Johnson');
/* SUBSTRING(str, pos, len) */
select
name,
concat(
substring(
name,
locate(' ',name) + 1,
25) ,
' ',
substring(name,1,1)
) formatted_name
from names
name | formatted_name |
---|---|
Vladimir Putin | Putin V |
Boris Johnson | Johnson B |