Re: How can i combine two columns

From: Peter Childs <blue(dot)dragon(at)blueyonder(dot)co(dot)uk>
To:
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How can i combine two columns
Date: 2003-02-12 11:40:14
Message-ID: Pine.LNX.4.44.0302121137240.15590-100000@RedDragon.Childs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, 12 Feb 2003, Ville Jungman wrote:

> hi
>
> how can i combine too cols to one.
>
> col1 | col2
> -----+-----
> 1 | 3
> 2 | 5
>
> select combine(col1,col2) from table; (or whatever the command will be)
> should give something like:
>
> combine
> -------
> 1
> 3
> 2
> 5
>

Simple

SELECT col1 as combine from table UNION ALL SELECT col2 from table;

UNION ALL because Union would remove any duplicates from the new
table. UNION ALL is also quicker than UNION.

Peter Childs.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jules Alberts 2003-02-12 12:27:33 Re: problem with pl/pgsql function unknown parameters
Previous Message Ville Jungman 2003-02-12 10:53:10 How can i combine two columns