在PostgreSQL中将2个视图合并为一个

在PostgreSQL中将2个视图合并为一个

本文介绍了在PostgreSQL中将2个视图合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做些完全疯狂的事情。我有2个具有相同列数的视图(虽然ID列除外,但列名不同),而且它们都碰巧有
2个现有的UNION查询。据我了解, UNION UNION ALL 仅在结合2个 SELECT 查询,在这里我试图结合其中的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 have2 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. 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个视图合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 22:19