gpt4 book ai didi

mysql - mysql左连接问题

转载 作者:行者123 更新时间:2023-11-29 08:58:18 25 4
gpt4 key购买 nike

您好,我有 2 个类似这样的表,

enter image description here

我想要的是获取类别和类别的部分标题,mySQL 看起来像这样,

SELECT `categories`.`category_id`, 
`categories`.`category_title`,
`categories`.`category_created`,
`section`.`section_id`,
`section`.`section_title`,
`categories`.`parent_section`
FROM (`categories`)
LEFT JOIN `section`
ON `section`.`section_id` = `categories`.`category_id`

但是,我返回的只是类别和部分的列表,而不是类别及其部分的列表。我是不是做错了什么?

最佳答案

如果您想要父部分,那么您的连接条件应该位于该列上:

SELECT `categories`.`category_id`, 
`categories`.`category_title`,
`categories`.`category_created`,
`section`.`section_id`,
`section`.`section_title`,
`categories`.`parent_section`
FROM (`categories`)
LEFT JOIN `section`
ON `section`.`section_id` = `categories`.`parent_section`

关于mysql - mysql左连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9331203/

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