I asked a similar question a couple months back. Located here: MySQL Query based on string
The problem I am running into is that this works in only one particular order and in some cases it works too well.
Here is a snippet of the data that this query is filtering out (duplicates are intended, actual data):
- BELLMORE
- ATLANTIC BCH
- ATLANTIC BEACH
- E HILLS
- EAST HILLS
- EAST ROCKAWAY
- FAR ROCKAWAY
- FLORAL PARK
- FLORAL PARK
- HIGHLAND HEIGHTS
- N HIGHLAND HGTS
- NORTH HIGHLAND HEIGHTS
The one query that helped in my last question (MySQL Query based on string) worked well for one instance and failed for the other instance. Here is the query:
select names from tablename group by substring_index(names," ",1)
Which returns:
- BELLMORE
- ATLANTIC BEACH
- EAST HILLS
- FAR ROCKAWAY
- FLORAL PARK
- HIGHLAND HEIGHTS
- N HIGHLAND HGTS
- NORTH HIGHLAND HEIGHTS
The problem with that one is that as you can see it removed a city that it should not have because it was only using the first word to group it by. The one it removed was:
- EAST ROCKAWAY
It was GROUP'ed BY EAST.
As I continue to write this I feel it is nearly impossible because the position of the static city name vs. the variable parts is always changing. Unless you can compare a certain amount of characters. Which is not flawless by far. If someone thinks they may have some insight or have worked with and accomplished such a thing I will appreciate the feedback and guidance. The ending result would be:
- BELLMORE
- ATLANTIC BEACH
- EAST HILLS
- EAST ROCKAWAY
- FAR ROCKAWAY
- FLORAL PARK
- HIGHLAND HEIGHTS
N=North,Hghts=Heights, etc.