繁体   English   中英

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

[英]MySQL SELECT with left join returns null on values from joined table

假设我有两个简单的表、 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM