gpt4 book ai didi

mysql - 使用第二个 INNER JOIN 或在第二个 INNER JOIN 之前对两个表进行 INNER JOIN 的 SQL

转载 作者:行者123 更新时间:2023-11-29 06:51:44 27 4
gpt4 key购买 nike

    select 
sld.linkid,sld.accept,scd.catid,scd.catname,scd.caturl,scd1.parentcatid
from sound_link_droos sld
INNER JOIN sound_cat_droos scd
ON sld.catid=scd.catid
OR
INNER JOIN sound_cat_droos scd1
ON sld.catid=scd1.parentcatid
WHERE accept = '1' AND scd.catname = '$catname'");

我想知道我是否可以在这个语句中拥有 or 或...如果一个内部连接返回错误

sound_cat_droos

Catidcatnameparentidaccepturl1David01http://www.example.com2爵士音乐11http://www.example.com

sound_link_droos

linkid链接名称catidaccepturl1我的爱11http://www.example.com/audio.mp32我的宝贝21 http://www.example.com/audio.mp3

最佳答案

您可以在 on 子句中表达 or 逻辑,如下所示:

select sld.linkid, sld.accept,s cd.catid, scd.catname, scd.caturl, scd1.parentcatid
from sound_link_droos sld inner join
sound_cat_droos scd
on sld.catid = scd.catid or sld.catid = scd.parentcatid
where accept = 1 and scd.catname = '$catname';

这样的连接通常会降低性能,而且这可能不会达到您真正想要的效果。如果没有,请使用示例数据和所需结果询问另一个问题。

我删除了 '1' 周围的单引号,因为我猜测该值是数字。应该将数字与数字进行比较。

还必须提及参数。您不应该使用参数值修改查询字符串。了解如何正确使用参数。

关于mysql - 使用第二个 INNER JOIN 或在第二个 INNER JOIN 之前对两个表进行 INNER JOIN 的 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47160425/

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