gpt4 book ai didi

mysql - 连接后显示表的所有行

转载 作者:太空宇宙 更新时间:2023-11-03 11:36:24 24 4
gpt4 key购买 nike

我想在连接来自表 B 的匹配列的元素后显示表 A 的所有行

表A

+-----------+----------+------------+
| FirstName | LastName | Date |
+-----------+----------+------------+
| Tia | Carrera | 1975-09-18 |
| Nikki | Taylor | 1972-03-04 |
| Yamila | Diaz | 1970-03-05 |
+-----------+----------+------------+

表B

+-----------+------------+
| code | Date |
+-----------+------------+
| 1234 | 1975-09-18 |
| 56789 | 1972-03-04 |
| 54856 | 1968-07-14 |
+-----------+------------+

我在网上找到的一切看起来都像

+-----------+----------+------------+-----------+
| FirstName | LastName | Date | code |
+-----------+----------+------------+-----------+
| Tia | Carrera | 1975-09-18 | 1234 |
| Nikki | Taylor | 1972-03-04 | 56789 |
+-----------+----------+------------+-----------+

但这就是我想要的结果

+-----------+----------+------------+-----------+
| FirstName | LastName | Date | code |
+-----------+----------+------------+-----------+
| Tia | Carrera | 1975-09-18 | 1234 |
| Nikki | Taylor | 1972-03-04 | 56789 |
| Yamila | Diaz | 1970-03-05 | |
+-----------+----------+------------+-----------+

最佳答案

你想要一个左连接:

select a.*, b.code
from a left join
b
on a.date = b.date;

关于mysql - 连接后显示表的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45616278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com