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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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 如何在2字符串中使用JOIN?_Mysql_Sql_Select_Join - Fatal编程技术网

Mysql 如何在2字符串中使用JOIN?

Mysql 如何在2字符串中使用JOIN?,mysql,sql,select,join,Mysql,Sql,Select,Join,我有两张桌子: 表1 Name Address Phone Nirdosh Kth 96749343 Hari pokhara 98493434 表2 Name Address Phone Shrestha Daldale 96749343 Hari pokhara 98493434 我想加入类型为字符串的名称字段,如下所示: select Table1.*,Table2.*

我有两张桌子:

表1

Name       Address     Phone
Nirdosh    Kth         96749343
Hari       pokhara     98493434
表2

Name       Address     Phone
Shrestha   Daldale     96749343
Hari       pokhara     98493434
我想加入类型为字符串的名称字段,如下所示:

select Table1.*,Table2.* 
from Table1 actual 
INNER JOIN Table2 more 
ON LIKE ('actual.Name') = LIKE('more.Name')

但是我得到了一个错误。

您使用的
like
操作符是错误的。您只需使用
=
运算符来比较字符串:

SELECT     Table1.*,Table2.* 
FROM       Table1 actual 
INNER JOIN Table2 more ON actual.Name = more.Name

您使用的
like
运算符是错误的。您只需使用
=
运算符来比较字符串:

SELECT     Table1.*,Table2.* 
FROM       Table1 actual 
INNER JOIN Table2 more ON actual.Name = more.Name

如果您认为Table2 Name,即more.Name不必与实际的.Name完全相同,您可以使用以下内容

select actual.*, more.*
from Table1 actual 
inner join Table2 more on more.Name like concat('%', trim(actual.Name), '%')

如果您认为Table2 Name,即more.Name不必与实际的.Name完全相同,您可以使用以下内容

select actual.*, more.*
from Table1 actual 
inner join Table2 more on more.Name like concat('%', trim(actual.Name), '%')

你想用
LIKE('actual.Name')=LIKE('more.Name')
做什么?这是一个相等比较吗?你得到了什么错误?你想用
LIKE('actual.Name')=LIKE('more.Name')
?这是一个相等的比较吗?你得到的错误是什么?