Skip to content
Advertisement

update record value if contains substring from other column

I have two tables, one containing all unique towns names in the UK and another one containing the human-inputted country of residence. Of course humans wrote stuff like “london, uk” or “cardiff, united kingdom”.

I need to consolidate the country_of_residence column so I have created a table with all possible towns, counties, cities and villages in the UK with almost 9000 records.

I want to update the column country_of_residence if its records contain any of the record in the column entity in the table uk_geo_entities.

I have read a lot answers here but they all try to update by wanting to check against or update one string, I need to do this against every record of a column.

and

run, but nothing happens.

After a working query I’d need to see

Advertisement

Answer

You can do it with EXISTS in the WHERE clause:

See the demo.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement