on 02-15-2024 12:54 PM - last edited 3 weeks ago by anne-petteroe
Hi there,
I wrote and executed the below query but it is fetching duplicate values as well. Kindly let me know what changes i need to do to get the unique results. I mean am i using any wrong tables in joining condition. I even tried INNER join still getting the same... PFA
QUERY I USED :
select DISTINCT top(2000) MARA.MATNR, BKPF.BUKRS, MSEG.WERKS, T001L.LGORT, BKPF.GJAHR, MSEG.BWART,
MKPF.XBLNR,
MSEG.DMBTR,
MSEG.MENGE,
MKPF.BUDAT,
MKPF.XABLN,
MBEW.PEINH,
MARD.LABST,
T156T.BTEXT
FROM MARA
INNER JOIN MSEG ON MSEG.MANDT=MARA.MANDT AND MSEG.MATNR=MARA.MATNR
INNER JOIN BKPF ON BKPF.MANDT = MSEG.MANDT AND BKPF.BUKRS = MSEG.BUKRS
INNER JOIN T001L ON T001L.MANDT = MSEG.MANDT AND T001L.WERKS = MSEG.WERKS AND T001L.LGORT = MSEG.LGORT
INNER JOIN MKPF ON MKPF.MANDT = BKPF.MANDT AND MKPF.MBLNR = BKPF.BELNR
INNER JOIN MBEW ON MBEW.MANDT=MSEG.MANDT AND MBEW.BWTAR=MSEG.BWTAR
INNER JOIN MARD ON MARD.MANDT=MBEW.MANDT AND MARD.LFGJA = MBEW.LFGJA
INNER JOIN T156T ON T156T.MANDT=MSEG.MANDT AND T156T.KZZUG=MSEG.KZZUG
WHERE MARA.MANDT ='500' AND
MARA.MATNR='1L90MBUS3.6/250' AND MSEG.WERKS='VNSD'AND BKPF.GJAHR='2022' AND T156T.SPRAS='E';
Hi,
T156T.BTEXT is the only field that is different for each record. So technically speaking you are not getting duplicate records.
Question is, are all the BTEXT values correct for the "duplicated" record?
If they are, you could look into STUFF and FOR XML to combine all values into one row.
If they are not, this "INNER JOIN T156T ON T156T.MANDT=MSEG.MANDT AND T156T.KZZUG=MSEG.KZZUG" needs another parameter.
Regards,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
select DISTINCT TOP(2000) MARA.MATNR,BKPF.BUKRS,MSEG.WERKS,T001L.LGORT,BKPF.GJAHR,MSEG.BWART,
MKPF.XBLNR,
MSEG.DMBTR,
MSEG.MENGE,
MKPF.BUDAT,
MKPF.XABLN,
MBEW.PEINH,
MARD.LABST,
T156T.BTEXT
FROM MARA
INNER JOIN MSEG ON MSEG.MANDT=MARA.MANDT AND MSEG.MATNR=MARA.MATNR
INNER JOIN BKPF ON BKPF.MANDT = MSEG.MANDT AND BKPF.BUKRS = MSEG.BUKRS
INNER JOIN T001L ON T001L.MANDT = MSEG.MANDT AND T001L.WERKS = MSEG.WERKS AND T001L.LGORT = MSEG.LGORT
INNER JOIN MKPF ON MKPF.MANDT = BKPF.MANDT AND MKPF.MBLNR = BKPF.BELNR
INNER JOIN MBEW ON MBEW.MANDT=MSEG.MANDT AND MBEW.BWTAR=MSEG.BWTAR
INNER JOIN MARD ON MARD.MANDT=MBEW.MANDT AND MARD.LFGJA = MBEW.LFGJA
INNER JOIN T156T ON T156T.MANDT=MSEG.MANDT AND T156T.KZZUG=MSEG.KZZUG
WHERE MARA.MANDT ='500' AND
MARA.MATNR='1L90MBUS3.6/250' AND MSEG.WERKS='VNSD'AND BKPF.GJAHR='2022' AND T156T.SPRAS='E';
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. For information, you have a menu "Edit Question". Here, what you did is to post a solution.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.