Subject | Re: [firebird-support] Strange left outer join behaviour |
---|---|
Author | Helen Borrie |
Post date | 2007-03-06T06:58:19Z |
At 05:07 PM 6/03/2007, you wrote:
TYPE...or, if you do, then they are double-quoted.
Try this:
SELECT
T1.ID,
T1.NAME,
COALESCE(SUM(T1."VALUE"), 0) <-------you had an unqualified column ref here
FROM T1
LEFT OUTER JOIN T2
ON T1.ID = T2.ID
WHERE
T2."TYPE" = :WANTEDTYPE
GROUP BY T1.ID, T1.NAME
If that doesn't fix it, come back and tell us what version of
Firebird you're using.
./heLen
>Hi all!First, I'm assuming you don't *really* have fields named VALUE and
>
>I have two tables, T1 and T2, which are linked by an ID (integer). T2
>has an ID, a TYPE field, which describes the type of the row, and a
>VALUE field.
>I am interested in all (or some - not important) rows of T1 and the
>SUM(VALUE) of T2 that has a given TYPE and is linked to T1.
>My query looks like this:
>SELECT T1.ID, T1.NAME, COALESCE(SUM(VALUE), 0)
>FROM T1 LEFT OUTER JOIN T2 ON T1.ID = T2.ID
>WHERE
> T2.TYPE = :WANTEDTYPE
>GROUP BY T1.ID, T1.NAME
>
>The strange thing is, that if there is no record from T2, then the T1
>master row is omitted from the result set as well.
>Example:
>If T1 has only one record, and T2 is empty, then the query returns no rows.
>In this case I would like to see the record from T1 too!
TYPE...or, if you do, then they are double-quoted.
Try this:
SELECT
T1.ID,
T1.NAME,
COALESCE(SUM(T1."VALUE"), 0) <-------you had an unqualified column ref here
FROM T1
LEFT OUTER JOIN T2
ON T1.ID = T2.ID
WHERE
T2."TYPE" = :WANTEDTYPE
GROUP BY T1.ID, T1.NAME
If that doesn't fix it, come back and tell us what version of
Firebird you're using.
./heLen