将2列合并为一列SQL [英] Combined 2 columns into one column SQL

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

问题描述

我是Postgres的初学者,需要做类似这样的事情。
我的Postgres查询输出有2列。我需要像下面这样结合这两个。

I'm a beginner to Postgres and need to do something like this. My Postgres query output has 2 columns. I need to combine these two like below.

第1列:

A
B
C

第2列:

D
D
D

输出列:

A
B
C
D

(第1列中的所有值和第2列中的不同值)

(all values from column 1 and distinct values from column 2)

在PostgreSQL中可能吗?

Is this possible in PostgreSQL?

推荐答案

有一种奇特的方式:

select distinct unnest(array[
        column1
        , column2
    ])
from table

这篇关于将2列合并为一列SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆