RE: [Info-ingres] Outer join problem
- From: "Peter Gale" <PGale@xxxxxxxxxxxxxxx>
- Date: Mon, 6 Mar 2006 12:13:45 -0000
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
.
- Follow-Ups:
- Re: [Info-ingres] Outer join problem
- From: Roy Hann
- Re: [Info-ingres] Outer join problem
- Prev by Date: [Info-ingres] Outer join problem
- Next by Date: Re: [Info-ingres] Outer join problem
- Previous by thread: Re: [Info-ingres] Outer join problem
- Next by thread: Re: [Info-ingres] Outer join problem
- Index(es):
Relevant Pages
|