I have the following data in mysql table:
Spring Texas
Corpus Christi Texas
Orange California
Los Angeles California
The right of the data will always be the state name. I want to run a sql query that shows only cities in California, and sets $city to an array of the city name portion of the returned string. Some cities have spaces such as los angeles and some don’t.
What is the best method to accomplish this to ensure I only get California cities, and only the city portion assigned to $city
Something like this, but is this the best way from an sql standpoint?
Select
terms.name
From
terms
Where
terms.name Like '%Texas%'
Try to normalize the data.
If you can’t, set up a table with state names.
Result
See the demo
If you can’t set up a table, then this query should do it: