我有以下查询

SELECT
    interview_content.title `title`,
    gallery_images.img_path img
FROM
    `interview`,
    `interview_content`,
    `gallery`,
    `gallery_images`
WHERE
    `gallery_images`.`id_parrent` = `gallery`.`id`
AND
    `gallery`.`id` =  `interview`.`gallery_id`
AND
    `gallery_images`.`default` = '1'
AND
    `interview`.`id` = `interview_content`.`id_parrent`
AND
    interview_content.id_lang = '2'
ORDER BY
    interview.date DESC


我需要在gallerygallery_images表上使用LEFT JOIN(即使没有画廊或默认图像也要获得interview.title

非常感谢

更新



问题出在第二左联接中。我无法让他们正确合作。当我尝试

SELECT
    interview_content.title `title`,
    gi.img_path img
FROM
    `interview`,
    `interview_content`
LEFT JOIN `gallery` as g ON g.`id` = `interview`.`gallery_id`
LEFT JOIN `gallery_images` as gi ON gi.id_parrent = g.`id`
WHERE
    `interview`.`id` = `interview_content`.`id_parrent`
AND
    interview_content.id_lang = '2'
ORDER BY
    interview.date DESC

it returns //Unknown column 'interview.gallery_id' in 'on clause'

最佳答案

你知道你需要做什么。
Google是您的朋友吗?

http://en.wikipedia.org/wiki/Join_%28SQL%29#Left_outer_join

关于php - 如何在此查询中使用LEFT JOIN,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5020074/

10-12 02:31