From: | "Rob Richardson" <Rob(dot)Richardson(at)rad-con(dot)com> |
---|---|
To: | <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Query help, please |
Date: | 2010-09-09 17:13:59 |
Message-ID: | 04A6DB42D2BA534FAC77B90562A6A03D015545EA@server.rad-con.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-novice |
Answering my own question:
In order to display a row that does not contain data, one must use an
outer join, but the question was what to join to. I created a table
named "numbers" with a single column named "number". I gave the table
eight rows, with the numbers 1 through 8. Then, the following query
worked:
select charge.charge, bases.base, bases.base_type, number, coil_id,
stack, stack_position
from charge
inner join bases on charge.base = bases.base
inner join base_type on bases.base_type = base_type.base_type
inner join numbers on number <= base_type.number_stacks
left outer join inventory on inventory.stack = number and
inventory.charge = charge.charge
where charge.charge = 37900
RobR
-----Original Message-----
Greetings!
A charge consists of a set of coils arranged in one or more stacks. It
is possible for a stack to be empty. I need a query that lists all
possible stacks, along with the coils that are in each stack (if any).
Charge 1 can have 4 stacks. Only stacks 2 and 3 are in use. A plain
ordinary query can get me:
Stack Coil Position
2 A 1
2 B 2
3 C 1
3 D 2
I need:
Stack Coil Position
1
2 A 1
2 B 2
3 C 1
3 D 2
4
The query is allowed to include the maximum possible number of stacks,
which is 8.
How can I get a result like this?
Thanks very much!
RobR
From | Date | Subject | |
---|---|---|---|
Next Message | tamanna madaan | 2010-09-09 19:23:10 | Re: error while autovacuuming |
Previous Message | Alban Hertroys | 2010-09-09 16:49:23 | Re: NOT IN vs. OUTER JOIN and NOT NULL |
From | Date | Subject | |
---|---|---|---|
Next Message | Mladen Gogala | 2010-09-09 17:44:15 | Re: logging table changes |
Previous Message | Rob Richardson | 2010-09-09 15:43:15 | Query help, please |