Re: If table A value IS NULL then table B - Mailing list pgsql-general

From Martín Marqués
Subject Re: If table A value IS NULL then table B
Date
Msg-id 1074888956.401180fcddd40@bugs.unl.edu.ar
Whole thread Raw
In response to If table A value IS NULL then table B  (Marco Lazzeri <marcomail@noze.it>)
Responses Re: If table A value IS NULL then table B  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
List pgsql-general
Mensaje citado por Marco Lazzeri <marcomail@noze.it>:

> I've got a table called 'main' described as follow
>
> CREATE TABLE main (
>   id_other_table INT,
>   value CHAR
> );
>
> and a table called 'other' described as follow
>
> CREATE TABLE other (
>   id INT PRIMARY KEY,
>   value CHAR
> );
>
> I want to write a query on table 'main' that if 'id_other_table' is null
> returns value from itself, from table 'other' otherwise.

SELECT CASE WHEN id_other_table IS NULL THEN id_other_table
       ELSE id
       FROM main,other

> Thank you very much, have a wonderful day!

Same for you.

--
select 'mmarques' || '@' || 'unl.edu.ar' AS email;
-------------------------------------------------------
Martín Marqués          |   Programador, DBA
Centro de Telemática    |     Administrador
               Universidad Nacional
                    del Litoral
-------------------------------------------------------

pgsql-general by date:

Previous
From: "Lee Harr"
Date:
Subject: Re: sequence in schema -- broken default
Next
From: "Joshua D. Drake"
Date:
Subject: Re: sequence in schema -- broken default