pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: jose antonio leo <jaleo8@storelandia.com>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Help with a query
Date: Fri, 25 Apr 2003 09:38:50 +0100
Message-ID: <200304250938.51060.dev@archonet.com> (raw)
In-Reply-To: <KAEFLIDKHEJNPPKOLGHMCELMDCAA.jaleo8@storelandia.com>
References: <KAEFLIDKHEJNPPKOLGHMCELMDCAA.jaleo8@storelandia.com>

On Friday 25 Apr 2003 8:41 am, jose antonio leo wrote:
> aec_cua_man:
> ac1-ac2-ac3
> 1-1-1
> 1-1-2
> 1-1-4
> 1-2-2
> ....
>
> aecoc:
> ac1-ac2-ac3-description
> 1-0-0-des1
> 1-1-0-des2
> 1-1-1-des3
> 1-1-2-des4
> 1-1-3-des5
> 1-1-4-des6
> 1-1-5-des7
> 1-2-0-des8
> 1-2-1-des9
> 1-2-2-des10
> ....
>
> I need the record of the first table with the fields ac1, ac2 and ac3
> equals than second table but in addition the fiels of the second table with
> a nul in the fiels ac2 and ac3.
>
> the table result will be:
> 1-0-0-des1
> 1-1-0-des2
> 1-1-1-des3
> 1-1-2-des4
> 1-1-4-des6
> 1-2-0-des8
> 1-2-2-des10
>
> Could you help me?

Simplest method might be a union - do the join on the 3 fields and union it 
with a simple select on aecoc where ac3=0 or ac2=0. Syntax is something like:

SELECT ac1,ac2,ac3,description FROM .... (join here)
UNION
SELECT ac1,ac2,ac3,description FROM aecoc... (grab zero descriptions here)

Note that the order of the result columns should be the same in both cases. If 
you know there will be no zeros in aec_cua_man then you might want to use 
UNION ALL.

See the User's guide Ch4 or the SQL SELECT reference for some details.

-- 
  Richard Huxton




view thread (16+ messages)  latest in thread

Message-ID: <200304250938.51060.dev@archonet.com>
Permalink:  ../200304250938.51060.dev@archonet.com/
Also on:    postgresql.org/message-id/200304250938.51060.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: dev@archonet.com, jaleo8@storelandia.com
  Subject: Re: Help with a query
  In-Reply-To: <200304250938.51060.dev@archonet.com>
  References: <KAEFLIDKHEJNPPKOLGHMCELMDCAA.jaleo8@storelandia.com> <200304250938.51060.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox