gpt4 book ai didi

php - 如何在此查询中使用 LEFT JOIN

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:27 24 4
gpt4 key购买 nike

我有以下查询

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(即使没有 gallery 也能获得 interview.title或默认图像)

非常感谢

更新


问题出在第二个 LEFT JOIN 中。我无法让它们一起正常工作。当我尝试

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 是你的 friend 吗?

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

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

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