首先,这个项目对我来说就像一个好奇心。
我正在为实用程序库编写一些代码,并正在添加运行不同类型的 SQL 连接语句的方法。一切都很好,但在某些时候我遇到了 SQL-92 规范(第 179 页)中包含的晦涩的 UNION JOIN
子句。
我不知道它有多大用处(我从未使用过它)并且它仅在 HyperSQL 中实现(据我所知)。
郑重声明,以下是它的工作原理。如果我们有两个表 T 和 U,其中包含任意数量的列/行:
====== T ===== === U ===
a b c d e
---- ---- ---- ---- ----
1 2 3 10 11
4 5 6 12 13
然后:
select * from T union join U
产生(没有特定的行顺序):
a b c d e
---- ---- ---- ---- ----
1 2 3 null null
4 5 6 null null
null null null 10 11
null null null 12 13
无论如何,我想知道哪些数据库确实支持它,或者您是否在野外见过它。
我也在考虑问它有什么好处,但我不希望这个问题以“主要基于意见”结束。
最佳答案
理论上,任何 SQL 都支持
如 "SQL Problems and Solutions" by Moiseenko 中所述:
This join type have been introduced in SQL-92 language standard, but disappeared in later versions of SQL standard. Particularly, it is absent from SQL2003 (ANSI and ISO). As many other structures of SQL, UNION JOIN is excessive because it can be expressed as substraction of full outer join and inner join. Formally, we can write this expression as follows:
A UNION JOIN B :=
(A FULL JOIN B)
EXCEPT
(A INNER JOIN B)
If DBMS does not support FULL JOIN (MySQL), it can be obtained via union of left and right outer joins. So our formula takes the form
A UNION JOIN B :=
((A LEFT JOIN B)
UNION
(A RIGHT JOIN B))
EXCEPT
(A INNER JOIN B)
实际上,SAS 支持它,至少是 9.3 版。引用:http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#p0o4a5ac71mcchn1kc1zhxdnm139.htm
关于sql - 哪些数据库支持 UNION JOIN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56343970/