I need to get the penultimate name from within a string.
For example;
Antonio Alves Ferreira Castro
I need the ferreira
I know that to get the Castro I can use the
SUBSTRING_INDEX(NOME, ' ', -1)
I tried -2, but it does not work.
I need to get the penultimate name from within a string.
For example;
Antonio Alves Ferreira Castro
I need the ferreira
I know that to get the Castro I can use the
SUBSTRING_INDEX(NOME, ' ', -1)
I tried -2, but it does not work.
This way:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('Antonio Alves Ferreira Castro', ' ', -2) , ' ', 1) penultimo_nome
Hugs.