Skip site navigation (1) Skip section navigation (2)

Re: If table A value IS NULL then table B

From: Martín Marqués <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: Marco Lazzeri <marcomail(at)noze(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: If table A value IS NULL then table B
Date: 2004-01-23 20:15:56
Message-ID: 1074888956.401180fcddd40@bugs.unl.edu.ar (view raw or flat)
Thread:
Lists: pgsql-general
Mensaje citado por Marco Lazzeri <marcomail(at)noze(dot)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
-------------------------------------------------------

In response to

Responses

pgsql-general by date

Next:From: Joshua D. DrakeDate: 2004-01-23 20:25:05
Subject: Re: sequence in schema -- broken default
Previous:From: Lee HarrDate: 2004-01-23 20:14:53
Subject: Re: sequence in schema -- broken default

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group