Split a column with a delimiter in SQLite

Let’s say you have a column with someone’s full name stored in the format of “LastName, FirstName” and you would rather have two columns – one with the first name and one with the last name. The below code to split out the names in your results window.

select 
	Name,
	TRIM(substr(Name, instr(Name,', ')+2)) AS first_name,
	TRIM(substr(Name, 1, instr(Name,', ')-1)) AS last_name
from table_name;

Posted

in

by