gpt4 book ai didi

如果连接表中没有记录,mysql 结果

转载 作者:行者123 更新时间:2023-11-29 22:03:54 25 4
gpt4 key购买 nike

我进行了搜索,但找不到答案。如果houses_availability中没有匹配的记录,我需要查看houses_houses中的记录。我知道这与 IS NULL 有关,但我尝试的一切都失败了。请帮忙。

SELECT 
houses_houses.*,
houses_availability.from_date
FROM
houses_houses
LEFT JOIN
houses_availability ON houses_houses.sid=houses_availability.housesid
WHERE
houses_availability.from_date>='2015-09-05'
AND
houses_availability.until_date<'2015-09-11'
ORDER BY houses_houses.sid LIMIT 0, 9

最佳答案

您检查 WHERE 子句中列出的 LEFT OUTER JOIN 上的 NULL:-

SELECT 
houses_houses.*,
houses_availability.from_date
FROM houses_houses
LEFT JOIN houses_availability
ON houses_houses.sid=houses_availability.housesid
AND houses_availability.from_date>='2015-09-05'
AND houses_availability.until_date<'2015-09-11'
WHERE houses_availability.housesid IS NULL
ORDER BY houses_houses.sid LIMIT 0, 9

值得注意的是,您不应在 WHERE 子句中检查 LEFT OUTER JOINed 表中的任何列,因为这会排除连接后的整行,而不是排除连接前的 LEFT OUTER JOINed 表行。因此,请检查 ON 子句中的日期范围

关于如果连接表中没有记录,mysql 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32348839/

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