From: aannddrree@libero.it
To: pgsql-sql@postgresql.org
Subject: left join and where
Date: 27 Dec 2001 12:28:43 -0800
Message-ID: <c837c0fc.0112271228.1ce47b3a@posting.google.com> (raw)
hello,
I'm a beginner and I have a trouble with SQL and Access 97
I try to explain the problem:
I have a table colori:
ID colore
1 red
2 blu
3 green
and a table Vendite
ID colore anno quantita
1 red 1 10
2 blu 1 20
3 green 2 30
I want a query that return all "quantita" but only for a year (for example
if year =1, I don't extarct green)
The result must be:
colore anno quantita
red 1 10
blu 1 20
green
------------------------------------
I use this SQL code
SELECT colori.colore, vendite.anno, sum(vendite.quantita)
FROM colori
LEFT JOIN vendite ON colori.colore=vendite.colore
WHERE vendite.anno=1 OR vendite.anno Is Null
GROUP BY colori.colore, vendite.anno
But the result is
colore anno quantita
red 1 10
blu 1 20
How can I get the correct result
Thank's for the help
Andrea
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: aannddrree@libero.it
Subject: Re: left join and where
In-Reply-To: <c837c0fc.0112271228.1ce47b3a@posting.google.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