Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 位置搜索查询问题_Mysql_Sql - Fatal编程技术网

Mysql 位置搜索查询问题

Mysql 位置搜索查询问题,mysql,sql,Mysql,Sql,我有以下三个表Location、Country和CountryAlias。我想找到这个国家的位置。表示我要根据国家/地区和国家/地区别名从位置表中搜索位置名称,并查找国家/地区代码。 但是当你喜欢查询的时候。我得到了错误的输出 位置 国家 乡下人 尝试查询 SELECT code from Country LEFT JOIN CountryAlias ON Country.code = CountryAlias.code where Country.`name` LIKE '%Bangalo

我有以下三个表Location、Country和CountryAlias。我想找到这个国家的位置。表示我要根据国家/地区和国家/地区别名从位置表中搜索位置名称,并查找国家/地区代码。 但是当你喜欢查询的时候。我得到了错误的输出

位置

国家

乡下人

尝试查询

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=输入和输出


两者都错了,有没有完美的解决方案。我正在使用Innodb engine for tables。

我没有看到使用Location表的查询,那么您希望如何找到班加罗尔?关于最后一个查询,它显示了您的请求。我猜您实际上不想使用LEFT join。@ypercube:I从该location表中获取该location\u名称并为该查询提供输入。如果可能的话,加入任何溶液。我也喜欢听这个!。但是我没有看到任何匹配的列。位置表是否只有一列:location\u name?您如何将位置名称作为查询的输入?是通过LIKE子句吗?location table有一些其他字段,但这些字段并不相关。输入来自另一个查询。这是从location_name列中获取的
code   alias
IN     Bharth
IN     Hindustan
SELECT code from Country 
LEFT JOIN CountryAlias ON Country.code = CountryAlias.code 
where Country.`name` LIKE '%Bangalore, India%' or CountryAlias.alias LIKE '%Bangalore, India%'
 SELECT code from Country 
    LEFT JOIN CountryAlias ON Country.code = CountryAlias.code 
    where Country.`name` LIKE '%India%' or CountryAlias.alias LIKE '%India%'