简体   繁体   English

SQL UNION算子如何识别重复

[英]How does SQL UNION operator identify duplicates

Executing the following SQL (on an PostgreSQL data base) results in 9 rows, even tough the data sets from both tables are obviously not completely identical.执行以下 SQL (在 PostgreSQL 数据库上)会产生 9 行,即使两个表中的数据集显然也不完全相同。

removed

Result:结果:

removed

Why does it not result in 13 rows?为什么它不会产生 13 行?

Using UNION ALL does the trick, but I am wondering how SQL UNION operator identifies duplicates?使用UNION ALL可以解决问题,但我想知道 SQL UNION运算符如何识别重复项?

UNION removes duplicates from the result set . UNION从结果集中删除重复项。 It guarantees that the result has no duplicates at all.它保证结果完全没有重复。 So, it removes duplicates both within tables and between tables.因此,它会删除表内和表之间的重复项。

You seem to have total duplicates within the tables.您似乎在表格中有重复项。 They are removed.它们被移除。

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

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