MYSQL' NOT IN'来自information_schema.tables的group_concat(table_name)语句

时间:2016-11-28 23:54:13

标签: mysql

在我的表格中' entites'我在列' tablename'中存储了一些表名。使用过的数据库。 现在我想获得不在entites.tablename

中的数据库的所有表名

以下是我的发言:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'codeigniter'
AND table_name COLLATE utf8_general_ci NOT IN (
    (SELECT concat(tablename) FROM codeigniter.entities)
)   

这种方法很好,但我并不认为这是最佳做法:

我的数据库以及所有表格和列都包含了&utff8_unicode_ci'整理, information_schema有' utf8_general_ci'排序规则。

表的结构' entites'在数据库codeigniter中:

(
    `id` int(32) NOT NULL AUTO_INCREMENT,
    `tablename` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 
AUTO_INCREMENT=13 ;

2 个答案:

答案 0 :(得分:0)

我不太了解你的桌面结构,但试试这个:

SELECT DISTINCT entities FROM entities.table WHERE NOT EXISTS (SELECT NULL FROM t2 WHERE table_schema = 'codeigniter')

来源:enter image description here

答案 1 :(得分:0)

您的子查询返回“codeigniter”架构中所有*表的单个串联字符串;除非你期望entity.table成为这样的连接,否则你将得不到你想要的结果。

这是A IN ("B", "C", "D")A IN ("B,C,D")

之间的差异

*“ALL”,因为group_concat调用的最大长度设置允许适合。

我的猜测是你只需要不使用GROUP_CONCAT

相关问题