mySQL连接表如果表1列值LIKE表2列值

时间:2021-02-07 17:07:28

Table 1

+-------+--------+--------+
| name  |  age   | gender |
+-------+--------+--------+
| mark  |  20    |  male  |
| john  |  22    |  male  |
| jenny |  21    | female |
+-------+--------+--------+

Table 2

+-------+----------+---------+
| name2 |  status  | address |
+-------+----------+---------+
| john  |  single  |  miami  |
| mark  |  single  | new york|
| jenny |  single  |  jersy  |
+-------+----------+---------+

I would like to display like this...
for Mark example:
Name: Mark
Age: 20
Gender: Male
Status: single
address: newyork
PLEASE USE "LIKE" not equal

我想这样显示......对于马克的例子:名字:马克年龄:20性别:男状态:单一地址:newyork请使用“LIKE”不等于

1 个解决方案

#1


1  

Basically, = is much preferred to use over LIKE because LIKE is used for pattern matching.

基本上,=更喜欢使用LIKE,因为LIKE用于模式匹配。

SELECT  a.name, a.age, a.gender,
        b.status, b.address
FROM    table1 a
        INNER JOIN table2 b
            ON a.name = b.name2

To further gain more knowledge about joins, kindly visit the link below:

要进一步了解联接,请访问以下链接:

if you really want to use LIKE,

如果你真的想用LIKE,

SELECT  a.name, a.age, a.gender,
        b.status, b.address
FROM    table1 a
        INNER JOIN table2 b
            ON a.name LIKE b.name2

#1


1  

Basically, = is much preferred to use over LIKE because LIKE is used for pattern matching.

基本上,=更喜欢使用LIKE,因为LIKE用于模式匹配。

SELECT  a.name, a.age, a.gender,
        b.status, b.address
FROM    table1 a
        INNER JOIN table2 b
            ON a.name = b.name2

To further gain more knowledge about joins, kindly visit the link below:

要进一步了解联接,请访问以下链接:

if you really want to use LIKE,

如果你真的想用LIKE,

SELECT  a.name, a.age, a.gender,
        b.status, b.address
FROM    table1 a
        INNER JOIN table2 b
            ON a.name LIKE b.name2