MariaDB左联接未返回预期结果

br

因此,为了尝试在python中进行一些自动的mariabackup恢复,即时通讯试图获取表及其上存在的任何外部约束的列表。我正在运行以下查询:

SELECT a.TABLE_NAME, b.CONSTRAINT_NAME from information_schema.tables a
LEFT JOIN information_schema.table_constraints b
    ON a.table_name = b.table_name
WHERE a.table_schema = 'world'
    AND b.constraint_type = 'FOREIGN KEY';

我的“世界”测试表上有3列-国家(没有FK),国家语言(一个FK)和城市(一个FK)。通过上面的查询,我希望有3个表,其中2个返回FK名称,而1个返回null,但是我得到的返回值只有2个带有FK的表。

我确定我错过了一些东西,但不能完全固定。

scaisEdge

您应该将左联接条件移到ON子句中,而不要移到哪里

    select a.TABLE_NAME
        , b.CONSTRAINT_NAME 
    from information_schema.tables a
    left join information_schema.table_constraints b
        on a.table_name = b.table_name
            and b.constraint_type = 'FOREIGN KEY';
    where a.table_schema = 'world'

如果在where子句中使用左联接表列,则此操作将作为内部联接..因此突出显示将左联接列的other子句扩展为ON条件

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章