From: | "Little, Douglas" <DOUGLAS(dot)LITTLE(at)orbitz(dot)com> |
---|---|
To: | Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, "Bierbryer, Andrew" <abierbryer(at)klsdiversified(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Right Join Question |
Date: | 2009-10-23 12:38:16 |
Message-ID: | A434C531E37AD442815608A769550D805908A0C23C@EGEXCMB01.oww.root.lcl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Andrew,
I think you want a full outer join. If I understood correctly, you want all real data, plus all codes without data.
Doug
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Scott Marlowe
Sent: Thursday, October 22, 2009 6:07 PM
To: Bierbryer, Andrew
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Right Join Question
On Thu, Oct 22, 2009 at 12:43 PM, Bierbryer, Andrew
<abierbryer(at)klsdiversified(dot)com> wrote:
> I am trying to solve the following problem. I have a certain column,
> to_state, that can take a finite set of values. I want to make sure that my
> query always returns those sets of finite values, even if not all of the
> values are represented in the results. In essence, I am looking to expand
> the result returned by the query by using a right join.
>
> When I do the following simple query, this seems to work.
>
> create table hat (the_hat integer);
> insert into hat values (1),(2),(3);
> create table cat (the_hat integer);
> insert into cat values (2),(3),(4),(5);
>
> select the_hat from hat
> right join cat c using(the_hat)
>
> The right join changes the results query from 1,2,3 to 2,3,4,5.
A right join will return all the rows on the right that aren't removed
by the where clause, and add the rows on the left that match, and
return nulls for those values where there is no match.
Perhaps you want a left join here?
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2009-10-23 13:05:40 | Re: FATAL error could not find function "alt_to_mic" in file cyrillic_and_mic.so |
Previous Message | Cjkalbente | 2009-10-23 12:26:33 | Re: Data migration tool certification |