gpt4 book ai didi

带有左连接的 MySQL SELECT 对连接表中的值返回 null

转载 作者:行者123 更新时间:2023-11-29 15:22:32 25 4
gpt4 key购买 nike

假设我有两个简单的表格,programsseasons:

programs
| id | season_id | title |
| 1 | 1 | Program 1 |
| 2 | 1 | Program 2 |
| 3 | 2 | Program 3 |

seasons
| id | season |
| 1 | Season 1 |
| 2 | Season 2 |

真的没有什么特别的,所以现在我运行以下命令:

SELECT
programs.title, seasons.season
FROM
programs
LEFT JOIN seasons ON programs.season_id = seasons.id;

给我留下的预期结果是:

| title     | season   |
| Program 1 | Season 1 |
| Program 2 | Season 1 |
| Program 3 | Season 2 |

然而实际结果如下:

| title     | season   |
| Program 1 | NULL |
| Program 2 | NULL |
| Program 3 | NULL |

是什么原因造成的以及如何补救?

最佳答案

根据您给出的表结构,它应该是seasons.season而不是seasons.name

关于带有左连接的 MySQL SELECT 对连接表中的值返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59289587/

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