How to split this address '1003 BRILEY PKWY, NASHVILLE, TN'

Viewed 29
Select
SUBSTRING_INDEX(OwnerAddress, ',' , -1),
SUBSTRING_INDEX(OwnerAddress, ',' , -2)
,SUBSTRING_INDEX(OwnerAddress, ',' , -3)
From mytable;

I want to split address, city and state in mysql from the field "OwnerAddress". The whole row which is address formatted like this "1003 BRILEY PKWY, NASHVILLE, TN".

1 Answers

Try this out

select SUBSTRING_INDEX(OwnerAddress, ',' , 1) as address,
SUBSTRING_INDEX(SUBSTRING_INDEX(OwnerAddress, ',' , 2),',',-1) as city,
SUBSTRING_INDEX(OwnerAddress, ',' , -1) as state 
From mytable;
Related