How to get the penultimate item of a string?

Asked

Viewed 42 times

2

I need to get the penultimate name from inside a string.

For example;

Antonio Alves Ferreira Castro

need the Ferreira

I know to catch the Castro I can use the

SUBSTRING_INDEX(NOME, ' ', -1)

tried the -2, but it does not work.

1 answer

2


Thus:

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

Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.