Re: Add one column to another

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Add one column to another
Date: 2011-08-25 17:50:14
Message-ID: m3vctlqt2h.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

(anonymous) wrote:

> I have to deal with a table which contains:

> first_name
> surname
> email1
> email2

> ... and I would like to create a view which combines both email columns thus:

> first_name
> surname
> email

> It looks simple but I can't think of an obvious query.

Try:

| SELECT first_name, surname, email1 AS email FROM testtable WHERE email1 IS NOT NULL UNION ALL
| SELECT first_name, surname, email2 AS email FROM testtable WHERE email2 IS NOT NULL;

Tim

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2011-08-25 17:54:05 Re: Add one column to another
Previous Message David Johnston 2011-08-25 14:53:33 Re: Add one column to another