比较mysql中的多个表
我有 4 个结构相同的表。 这 4 个表是从另一个表(主表)生成的。
- 主表-> A(10 000 行)
- 表 1 -> a1(2000行)
- 表 2 -> a2(3000 行)
- 表 3 -> a3(4000行)
- 表 4 -> a4(1 000 行)
假设4个生成的表是不相交的,它们的总和等于表A。
但我需要确认这一点。
我的问题:我如何比较这4个表,看看它们是否有共同的id?
我知道我可以构建很多查询来内连接 a1 和 a2、a1 和 a3 等等。
但我认为这应该是另一种更好的方式。
I have 4 tables with the same structure.
This 4 tables are generated from another one, the main table.
- Main table -> A (10 000 rows)
- table 1 -> a1 (2 000 rows)
- table 2 -> a2 (3 000 rows)
- table 3 -> a3 (4 000 rows)
- table 4 -> a4 (1 000 rows)
It's supposed that 4 generated tables are disjoint, and their sum is equal to table A.
But i need to confirm this.
My question: How i compare this 4 tables, to see if they have any id in common?
I know that i can build a lot of querys to inner join a1 with a2, a1 with a3 and so on.
But i think that should be another better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是将每个表中的所有 id
union all
组合在一起,group by
每个,并检查是否有任何 id 计数超过 1如果任何 id 出现多次,它将显示在该查询的结果中。
I would just
union all
together all the ids from each table,group by
each, and check whether any have counts more than oneIf any id occurs more than once, it will show up in the results of this query.