RE: [Info-ingres] Outer join problem



Of course you may well ask why it is necessary to ifnull(t3.acct,''). I may
be wrong here but because there is no actual join between t1 and t3 this
results is a cart prod left join between t1 and t3. t3.acct is being used
after that outer join, hence it is null.

--
Peter Gale
Comprehensive Solutions International
T: +44 (0)1398 341777 M: +44 (0)7831 513181
PGale@xxxxxxxxxxxxxxx www.Comp-Soln.co.uk

-----Original Message-----
From: info-ingres-admin@xxxxxxxxxxxxxxx
[mailto:info-ingres-admin@xxxxxxxxxxxxxxx] On Behalf Of Peter Gale
Sent: 06 March 2006 12:31
To: Piotr.Wisniewski@xxxxxxxxxxxx; info-ingres@xxxxxxxxxxxxxxx
Subject: RE: [Info-ingres] Outer join problem

Because that first comparison t1.id=t2.bank_id is not comparing NULLS. It
compares the rows in t1 with t2. There are no rows in t2 so the outer join
returns nulls for the t2 columns which are then used in the outer join for
t3.

--
Peter
T: +44 (0)1398 341777
PGale@xxxxxxxxxxxxxxx


-----Original Message-----
From: Piotr.Wisniewski@xxxxxxxxxxxx [mailto:Piotr.Wisniewski@xxxxxxxxxxxx]
Sent: 06 March 2006 12:25
To: PGale@xxxxxxxxxxxxxxx; info-ingres@xxxxxxxxxxxxxxx
Subject: RE: [Info-ingres] Outer join problem

Ok.,
So why does

select t1.*
from tmp1 t1
left join tmp2 t2 on t1.id=t2.bank_id

return 2 rows ?


-----Original Message-----
From: Peter Gale [mailto:PGale@xxxxxxxxxxxxxxx]
Sent: Monday, March 06, 2006 1:14 PM
To: Piotr.Wisniewski@xxxxxxxxxxxx; info-ingres@xxxxxxxxxxxxxxx
Subject: RE: [Info-ingres] Outer join problem

Hi Piotr,

NULLS!!!!!

As you are outer joining an outer join there is the potential for NULLS
being joined to NULLS, the result of which is completely undefined.

t2.bank_nr will be null in the join as will t3.acct. Wrap them up in
suitable IFNULL statements and the desired result is obtained.

select t1.*
from tmp1 t1
left join tmp2 t2 on t1.id=t2.bank_id
left join tmp3 t3 on
t1.acct=varchar(ifnull(t2.bank_nr,''))+ifnull(t3.acct,'')



--
Peter Gale
Comprehensive Solutions International
T: +44 (0)1398 341777 M: +44 (0)7831 513181
PGale@xxxxxxxxxxxxxxx www.Comp-Soln.co.uk

-----Original Message-----
From: info-ingres-admin@xxxxxxxxxxxxxxx
[mailto:info-ingres-admin@xxxxxxxxxxxxxxx] On Behalf Of
Piotr.Wisniewski@xxxxxxxxxxxx
Sent: 06 March 2006 12:00
To: info-ingres@xxxxxxxxxxxxxxx
Subject: [Info-ingres] Outer join problem

In my opinion the following SELECT should return 2 rows.
It returns 0 rows on ingres 2.6 and r3.

The SQL docs say: outer joins are evaluated left to right by default.
If table tmp1 is non empty then the SELECT of the form
SELECT ........
FROM tmp1
LEFT JOIN tmp2 ON cond1
LEFT JOIN tmp3 ON cond2

should be nonzero no matter what the conditions cond1, cond2 are.

Am I right or not ?

Piotr


-----------------------------------------------------
create table tmp1 (id i1, acct varchar(8) );
insert into tmp1 values (1, '');
insert into tmp1 values (2, '');

create table tmp2 (bank_id i4, bank_nr varchar(8) );
create table tmp3 (nl_id i4, acct varchar(8) );

select t1.*
from tmp1 t1
left join tmp2 t2 on t1.id=t2.bank_id
left join tmp3 t3 on t1.acct=varchar(bank_nr)+t3.acct
;
rollback\g
_______________________________________________
Info-ingres mailing list
Info-ingres@xxxxxxxxxxxxxxx
http://mailman.cariboulake.com/mailman/listinfo.py/info-ingres

_______________________________________________
Info-ingres mailing list
Info-ingres@xxxxxxxxxxxxxxx
http://mailman.cariboulake.com/mailman/listinfo.py/info-ingres

.



Relevant Pages

  • RE: [Info-ingres] Outer join problem
    ... left join tmp2 t2 on t1.id=t2.bank_id ... Subject: [Info-ingres] Outer join problem ... As you are outer joining an outer join there is the potential for NULLS ...
    (comp.databases.ingres)
  • RE: [Info-ingres] Outer join problem
    ... Because that first comparison t1.id=t2.bank_id is not comparing NULLS. ... There are no rows in t2 so the outer join ... Subject: [Info-ingres] Outer join problem ... If table tmp1 is non empty then the SELECT of the form ...
    (comp.databases.ingres)
  • Re: Space required for an empty varchar field?
    ... >who don't understand how to deal with NULLS. ... as they'll be in the result set of an outer join. ... it gets unwieldy fast if you have multiplle NULLable columns. ... Thanks Hugo. ...
    (microsoft.public.sqlserver.programming)
  • Re: Second opinion for a query
    ... LEFT OUTER JOIN dbo.tblImage ... You should judge by yourself if you think it's better. ... back to this query in a year or so from now. ... There are a lot of people claiming that NULLs should be avoided, ...
    (microsoft.public.sqlserver.programming)
  • RE: [Info-ingres] Outer join problem
    ... As you are outer joining an outer join there is the potential for NULLS ... If table tmp1 is non empty then the SELECT of the form ... should be nonzero no matter what the conditions cond1, cond2 are. ...
    (comp.databases.ingres)