Re: Help with subselect (first time)

From: "Rodolfo J(dot) Paiz" <rpaiz(at)simpaticus(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Help with subselect (first time)
Date: 2005-02-04 23:46:27
Message-ID: 1107560787.5469.122.camel@rodolfo.gt.factorrent.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, 2005-02-03 at 13:04 -0600, Rodolfo J. Paiz wrote:
> I will guess in advance that I'm missing something obvious, but I
> *think* I need a subselect here and I've never done those.

Following up on this thread, I've decided that it's impossible to use a
subselect for this purpose. Wrong tool. Now investigating joins...

For simplicity's sake's, let's say I have a query which returns this:

| month | days |
|-----------|------|
| 2005-01 | 31 |
|-----------|------|
| 2005-02 | 28 |
|-----------|------|
| 2005-03 | 31 |
|-----------|------|

And I have a second query which returns this:

| month | flts |
|-----------|------|
| 2005-01 | 11 |
|-----------|------|
| 2005-03 | 8 |
|-----------|------|

Is there a simple way to join those two result sets into one? What I'd
like to have is this:

| month | days | flts |
|-----------|------|------|
| 2005-01 | 31 | 11 |
|-----------|------|------|
| 2005-02 | 28 | 0 |
|-----------|------|------|
| 2005-03 | 31 | 8 |
|-----------|------|------|

Since I'm not always able to fly every month, the "flts" result set will
not have data for every month. In that case, I'd like to show a zero
value as shown above.

Can someone point me to the right part of the manual to read? Thanks!

Cheers,

--
Rodolfo J. Paiz <rpaiz(at)simpaticus(dot)com>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2005-02-05 01:43:35 Re: Help with subselect (first time)
Previous Message Luis Cuenca 2005-02-04 21:37:13 pg_hba.cong edit