您好,我有 2 个类似这样的表,
我想要的是获取类别和类别的部分标题,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/