Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Duplication of lines in LEFT JOIN

Hi all,

There is an issue I can't seem to resolve. When I do a left join certain lines duplicate.The second gets empty fields except for the table keys (sipNo ma_kod desen varyant) . I think it's caused by the auto joining of tables but I am not sure.

I believe the second left join(in red) where I join siparis table to irsaliye table is the causing the problem. When I comment out the irsKesilmemis(in green) from sipstok table it seems to work fine.  Please help!!

Here is my code:

ODBC CONNECT32 TO RAPOR;

   

siparis:

LOAD *;

SQL SELECT ol_or_no1, ol_or_no2 AS sipNo, ol_sr AS sira, ol_ma_kod AS ma_kod, ol_qty, ol_sqty_mt, ol_kapa, ol_ds_kod AS desen, ol_vry AS varyant, ol_plan_onay, date(ol_wrk_basdt), date(ol_onaydt),date(ol_terdt),

                               ol_or_anhno, ol_onay2, date(ol_onay2dt),or_pe_no, or_anhno, or_rr_no

          FROM DBA.ordln

          JOIN DBA.ord

          ON ordln.ol_or_anhno = ord.or_anhno

          WHERE ol_kapa = 'A' /*AND (date(ol_onaydt) BETWEEN '$(basTarih)' AND '$(bitisTarih)')*/

          order by sipNo, sira, ma_kod, desen, varyant

;

irsaliye:

LOAD *;

 

SQL SELECT a.sh_ma_kod AS ma_kod, a.sh_ds_kod AS desen, a.sh_vry AS varyant, a.sh_of_or_no2 AS sipNo, a.sh_of_ol_sr AS sira,

                       sum(CASE WHEN sh_sf_hk_no = 30 AND sf_ir_no = 0 THEN a.sh_qty_mt ELSE 0 END) as irsKesilmemis

          FROM DBA.stkhar AS a

          LEFT JOIN DBA.stkfis AS b

          ON a.sh_sf_anhno = b.sf_anhno

          WHERE  a.sh_sf_no1 = 2012 AND sh_sf_hk_no = 30 AND sf_ir_no = 0

          group by sipNO, sira, ma_kod, desen, varyant

;

stok:

Load

     *,

     brutStok-standartStok as kMetrajStok;

  

SQL SELECT   a.sh_ma_kod AS ma_kod, a.sh_ds_kod AS desen, a.sh_vry AS varyant,

                              sum(CASE WHEN a.sh_sf_hk_no < 30 THEN a.sh_qty_mt ELSE -1*a.sh_qty_mt END) AS brutStok,

                              sum(CASE WHEN (a.sh_sf_hk_no < 30 AND a.sh_qty_mt = b.ma_kg_top) THEN a.sh_qty_mt

                                                   WHEN (a.sh_sf_hk_no >= 30 AND a.sh_qty_mt = b.ma_kg_top) THEN -1*a.sh_qty_mt

                                                   ELSE 0*a.sh_qty_mt END)as standartStok

       FROM DBA.stkhar AS a

       LEFT JOIN DBA.mam AS b

       ON a.sh_ma_kod = b.ma_kod

       WHERE  a.sh_sf_no1 = 2012

       GROUP BY  a.sh_ma_kod, a.sh_ds_kod, a.sh_vry

       order by  ma_kod, desen, varyant

;

LEFT JOIN (siparis) LOAD * resident stok;

LEFT JOIN (siparis) LOAD * resident irsaliye;

sipstok:

LOAD

                              sipNo,sira, ma_kod, desen, varyant, ol_qty, standartStok,ol_sqty_mt, irsKesilmemis,

 

                                        if(rowno()=1,

                                     standartStok,

                                             if(ma_kod = previous(ma_kod) AND desen = previous(desen) and varyant = previous(varyant) ,

                                          Peek(ATP)- Previous(ol_qty), standartStok)

                                           ) as ATP,

                             

                                                  if(

                                                  if(ma_kod=previous(ma_kod) AND desen = previous(desen) and varyant = previous(varyant) ,

                                          Peek(ATP)-Previous(ol_qty), standartStok)>= (ol_qty - irsKesilmemis), now(),

                                          ) AS planTarih

                                         

                                         

                                                

resident siparis;

    

store sipstok into planlama1.qvd (qvd);

Here is a sample from the resulting table: look at lines where sıra = 10 or 11

sipNosirama_koddesenvaryantstandartStokATPirsKesilmemisol_qtyol_sqty_mtplanTarih
8051SK3022-08 13501350,0003501035010017.10.2012 12:20:57
8892ME1005-011019580580,00010001000017.10.2012 12:20:57
8894ME1005-0110810 10000
8894ME1005-011081
8896ME1005-0110811120120,0002001000200
8899ME1005-01110412401240,00010001000017.10.2012 12:20:57
88910ME1005-011111120 10000
88910ME1005-011111
88911ME1005-0111314320 10000
88911ME1005-011131
88912ME1005-01113448804880,00010001000017.10.2012 12:20:57
88913ME1005-016342840840,00010001000017.10.2012 12:20:57
88914ME1005-01634516801680,00010001000017.10.2012 12:20:57

Thanks a lot

2 Replies
Not applicable
Author

Maybe not a great solution but for testing the issue have you tried loading distinct?

LEFT JOIN (siparis) LOAD distinct * resident irsaliye;


Not applicable
Author

doesn't work