cancel
Showing results for 
Search instead for 
Did you mean: 

Why am i getting duplicates even after using DISTINCT any wrong join i have used?

Albatross
Explorer
0 Kudos

Hi There!
I wrote this query to achieve the attached output... But it is giving me improper/duplicated results. The data have 464 rows but i'm getting 1008 rows. Kindly let me know what mistake I made in the join conditions.  Thanks in advance.

 

select distinct T001L.LGORT as sloc,MKPF.BUDAT as Year,MKPF.XBLNR as ReferenceDoc,MKPF.XABLN as GRGISlip,
MSEG.BWART as MovementType,MSEG.SHKZG as DC,
(select case MSEG.SHKZG when 'S' then MSEG.MENGE else 0.0 end) as Receipt,

(select case MSEG.SHKZG when 'H' then MSEG.MENGE else 0.0 end) as Issue,
MSEG.DMBTR as Amount,MSEG.MENGE as BalQuantity,
MBEW.VERPR as PricePerUnit, MBEW.SALK3 as BalanceAmount,
t156t.BTEXT as Comment from mara

INNER join mseg  on 

mara.MATNR=mseg.MATNR

INNER  join t001l 

on t001l.LGORT=mseg.LGORT
 
INNER  join mkpf 

on mkpf.MBLNR=mseg.MBLNR 


INNER  join mard 

on mard.MATNR=MARA.MATNR 


INNER join mbew 

on mbew.MATNR=MARA.MATNR 

AND MBEW.LVORM=MARA.LVORM 

INNER JOIN t156t 

     ON  t156t.bwart = mseg.bwart 

     AND t156t.sobkz = mseg.sobkz 

     AND t156t.kzbew = mseg.kzbew 

     AND t156t.kzzug = mseg.kzzug 

     AND t156t.kzvbr = mseg.kzvbr

where 

MARA.MATNR='1L90MHVB10250A'

and (MKPF.budat between '20200101' and '20231231') 

and MSEG.BUKRS='VN01' and MSEG.WERKS='VNSD' AND t001l.lgort='RM01'and t156t.SPRAS='E' ;

 


 

Sandra_Rossi
Active Contributor
0 Kudos
Please stop using meaningless titles like "PLEASE HELP", we know you're asking some help. Use the tags to indicate the question category, use the title to indicate the topic which is "SELECT duplicate results". Thank you.
Albatross
Explorer
0 Kudos
Hi @Sandra as I'm new to this no idea on what to put in the title... I'll put meaningful title from now. Anyway thanks for pointing out my mistake.
Sandra_Rossi
Active Contributor
0 Kudos
It's still time to edit the title of your question. Don't delay what you can do now 😉
Albatross
Explorer
0 Kudos
Done buddy...changed the title now. By the way any idea on my query? Can u have a look on that once.@sandra
Sandra_Rossi
Active Contributor
0 Kudos
As I said one week ago: "You can find by yourself why the query gives duplicate lines, by removing one table at a time till you get unique lines: it's the last table removed which makes the duplicate lines."

Accepted Solutions (0)

Answers (0)