首页 > 解决方案 > 将基于 table_1 列值的两个表连接到匹配的 table_2 列名?

问题描述

是否可以根据表 1 列值等于 table_2 列名将 2 个表连接在一起?

table_1     table_2
-----    -------------
| A |    | 1 | 2 | 3 |
|---|    |-----------|
| 1 |    | Q | W | E |
-----    -------------

期望的结果是:

Select A from table_1 join table_2 WHERE table_1 A = table_2 column name.

Result:
1Q

我正在使用 PHP,对于可怜的 psudo SQL 感到抱歉,老实说,我不知道如何措辞。感谢您提供的任何帮助!

标签: phpmysqljoin

解决方案


SELECT CONCAT(table_1.A,"",table_2.1) as RESULT
FROM table_1 
LEFT JOIN table_2 ON table_1.A = table_2.1

推荐阅读