gpt4 book ai didi

MySQL:在可能为 NULL 的字段上加入表

转载 作者:太空宇宙 更新时间:2023-11-03 11:19:49 25 4
gpt4 key购买 nike

我有两个表(版本和格式)和一个链接到它们的字段 - bar_code。我遇到的问题是这个选择语句:

SELECT
Release.name,
Release.default_upc,
Artist.name,
Artist.url_name,
Format.*
FROM
releases AS Release,
artists AS Artist,
formats AS Format
WHERE
Release.id IN(20015, 2414) AND
Artist.id = Release.artist_id AND
Format.bar_code = Release.default_upc

问题是当 Release.default_upc = null 时,不会返回任何记录。但是,default_upc 可以为 null 是一种有效的行为,如果是,查询应该尝试寻找 Format.bar_code = null 的格式 - 而不是只返回其他选定的数据。

实际上不确定这在 MySQL 中是否 100% 可行,但可以接受任何建议。

最佳答案

使用外连接。

One site that explains

Another one

关于MySQL:在可能为 NULL 的字段上加入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1907819/

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