在PostgreSQL中将2个视图合并为一个 [英] Combining 2 views into one in PostgreSQL
问题描述
我需要做些完全疯狂的事情。我有2个具有相同列数的视图(虽然ID列除外,但列名不同),而且它们都碰巧有
2个现有的UNION查询。据我了解, UNION
和 UNION ALL
仅在结合2个 SELECT $ c $时有效c>查询,在这里我试图结合其中的4个!又就是2个视图。
I need to do something completely insane. I have 2 views that have the same number of columns (different column names though except the ID column) and they both happen to have
2 existing UNION queries. From my understanding UNION
and UNION ALL
only work when combining 2 SELECT
queries, here I'm trying to combine 4 of them! Aka the 2 views.
推荐答案
据我了解,UNION和UNION ALL仅在组合2个SELECT查询时才起作用
"from my understanding UNION and UNION ALL only work when combining 2 SELECT Queries"
Ummmm ... no 。您可以执行以下操作:
Ummmm...no. You can do something like the following:
select col1,col2
from table
union all
select col1,col2
from some_other_table
union all
select col1,col2
from yet_another_table;
等,等等。
这篇关于在PostgreSQL中将2个视图合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!