如何根据相同的列名连接两个 MySQL 表?

How to join two MySQL tables based on the same column name?

我有 2 个不同的 table。两者都有几个不同的列,但是在这两个 table 中都有一列 serial_number 具有重复的序列号。

在 table 1 中,如果 serial_number 在两个 table 中都匹配,我想附加 table 2 的行数据。

示例:

Table 1

id, serial_number, name  , phone     , email
 1, 87454126     , Chris , 5105487451, example@example.com

Table 2

id, serial_number, status   , reason
 1, 87454126     , Completed, Some Reason

我想要的结果:

Table 1 变为:

1, 87454126, Chris, 5105487451, example@example.com, Completed, Some Reason

请帮帮我,我想不通。谢谢

您可以为两个表指定不同的名称并像这样连接:

SELECT *
FROM Table1 AS t1
JOIN Table2 AS t2 ON t1.serial_number = t2.serial_number;