繁体   English   中英

为什么 MySQL5.7 似乎忽略了子查询

[英]Why MySQL5.7 seems to ignore subquery

我有以下 SQL 查询,它的行为与我在 MySQL 8 中的预期一致,但在 5.7 版中没有产生相同和正确的结果,我不知道为什么......

SELECT concat(table_name, '_', column_name) as missing
    from information_schema.columns
    where table_schema = 'ref_schema' and table_name in ('aliases','indiv') and
            concat(table_name, '_', column_name) not in (
                select concat( columns.table_name,'_',columns.column_name) as v
                from information_schema.columns   
                where table_schema = 'new_schema' 
    );

该查询基本上是比较 2 个模式(ref_schema 和 new_schema)中的 2 个表(别名和 indiv)结构,并且应该列出第二个中缺少的列......

假设两个模式中的表结构相同,它应该返回 0 行。 它与 MySQL8 的关系。 但在 5.7 版中,它返回完整的列集。 似乎没有正确执行“NOT IN”条件。

我使用 MySQL8 进行调试。 5.7 用于生产。 所以我需要让它在 5.7 上运行。

任何帮助,将不胜感激。

应用 Akina fix 给出了正确的答案并解决了我的问题:

SELECT concat(table_name, '_', column_name) as missing
FROM information_schema.columns
WHERE
    table_schema = 'ref_schema' and
    table_name in ('aliases','indiv') and
    (table_name,column_name) not in (
        select table_name,column_name
        from information_schema.columns   
        where table_schema = 'new_schema' 
    );

现在,两个平台都提供相同且准确的结果。 语法更容易阅读!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM