Discussion:
Multiple Inner and Left Joins
(too old to reply)
Alastair Williamson
2009-03-03 11:17:32 UTC
Permalink
Hello,

I am trying to find the correct sql query syntax to join multiple tables
together including at least two left joins. I have 1 master table which
inner joins to 4 tables and then left joins to 2. The inner joins are
obviously no problem but I can only get one of the left joins working.

Does anyone have a working example of a query with such a join in it?

Many thanks

Aly
Jakub Otrzasek
2010-04-19 14:15:21 UTC
Permalink
Post by Alastair Williamson
Hello,
I am trying to find the correct sql query syntax to join multiple tables
together including at least two left joins. I have 1 master table which
inner joins to 4 tables and then left joins to 2. The inner joins are
obviously no problem but I can only get one of the left joins working.
Does anyone have a working example of a query with such a join in it?
Many thanks
Aly
select t.naz,t.kod_p,t.rp,
case when j.war is null then 1 else war end war,
case when j.wym_x is null then t.wym_x else j.wym_x end wym_x,
case when j.wym_y is null then t.wym_y else j.wym_y end wym_y,
case when j.wym_z is null then t.wym_z else j.wym_z end wym_z,

case when j.wag_n is null then t.wag_n else j.wag_n end wag_n,
case when j.wag_b is null then t.wag_b else j.wag_b end wag_b,
t.kod_3,t.kod_2
from interface.imperr
inner join ***@PROD t on
err_what = 1002 and err_errid=0
and t.kod_2 = err_whatid and
err_system = t.kod_3
left outer join ***@PROD j on
j.tow_kod = t.kod and
j.cjm = 'Opakowanie' and
--t.wsk_d='T' and akt='T' and
t.kod_3 in (1,2)
left outer join interface.imptwr_iface i on
twr_numer =t.kod_2 and
twr_System = t.kod_3
where twr_numer is null;

regards
j.

Loading...