Re: RV: bad result in a query!! :-(
От | Jochem van Dieten |
---|---|
Тема | Re: RV: bad result in a query!! :-( |
Дата | |
Msg-id | 1034864061.3daec5bddd7e7@webmail.oli.tudelft.nl обсуждение исходный текст |
Ответ на | RV: bad result in a query!! :-( ("Jose Antonio Leo" <jaleo8@storelandia.com>) |
Ответы |
Re: RV: bad result in a query!! :-(
|
Список | pgsql-general |
Query rewritten with some indentation: SELECT vtdiaaec.cod_ae1, aecoc.des_ae, Sum(vtdiaaec.ven_uni) AS -- You are missing something here, copy-paste error I presume Sum(vtdiaaec.ven_pco) AS SumaDeven_pco, Sum(vtdiaaec.ven_siv) AS SumaDeven_siv, Sum(vtdiaaec.ven_civ) AS SumaDeven_civ, Sum(vtdiaaec.ven_ofe) AS SumaDeven_ofe, Sum(vtdiaaec.cos_ofe) AS SumaDecos_ofe FROM vtdiaaec LEFT JOIN aecoc ON vtdiaaec.cod_ae1 = aecoc.cod_ae1 WHERE aecoc.cod_ae2=0 AND aecoc.cod_ae3=0 AND aecoc.cod_ae4=0 AND aecoc.cod_ae5=0 AND extract (year from vtdiaaec.fecha)='2002' GROUP BY vtdiaaec.cod_ae1, aecoc.des_ae ORDER BY vtdiaaec.cod_ae1; > The table aecoc has a primary key (cod_ae1,cod_ae2,cod_ae3) and the > table vtdiaaec has a key with the fields cod_ae1,cod_ae2,cod_ae3. Something I don't understand about this query: why the LEFT JOIN and not an INNER JOIN? Isn't it true that each row of the vtdiaaec table that does not have a matching row in aecoc table gets included in the join result with each field that originates from the aecoc table set to NULL? But then, you later remove the rows anyway by adding predicates that exclude all rows where these fields do not have a 0 value. Wouldn't you get the same result by using an INNER JOIN instead of a LEFT JOIN? Or am I missing something? Jochem
В списке pgsql-general по дате отправления: