I have the following three tables Location, Country and CountryAlias. I want to find the locations country. Means I want to search location_name from location table against Country and CountryAlias and find the country code. But while do like query. I am getting wrong output.
location
location_name
Bangalore, India
India
Chennai, India
Country
code name
IN India
IO British Indian Ocean Territory
CountryAlias
code alias
IN Bharth
IN Hindustan
Try Query
SELECT code from Country
LEFT JOIN CountryAlias ON Country.code = CountryAlias.code
where Country.`name` LIKE '%Bangalore, India%' or CountryAlias.alias LIKE '%Bangalore, India%'
O/P = NuLL
SELECT code from Country
LEFT JOIN CountryAlias ON Country.code = CountryAlias.code
where Country.`name` LIKE '%India%' or CountryAlias.alias LIKE '%India%'
O/P = IN and IO
Both wrong, Is there any perfect solution. I am using Innodb engine for tables.