Obiettivo
Devi dividere un testo in parti separate in MySQL.
Esempio
La tabella Student contiene id e name, con nomi completi come Ann Smith.
Soluzione
SELECT SUBSTRING_INDEX(name, ' ', 1) AS firstname, SUBSTRING_INDEX(name, ' ', -1) AS lastname FROM Student;Come funziona
SUBSTRING_INDEX() accetta stringa, delimitatore e numero di occorrenze. Un valore positivo conta da sinistra, uno negativo da destra.