How do I get the penultimate item in a string?

2

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.

    
asked by anonymous 02.09.2016 / 01:03

1 answer

2

This way:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('Antonio Alves Ferreira Castro', ' ', -2) , ' ', 1) penultimo_nome

Hugs.

    
02.09.2016 / 01:21