Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Optimize SQL Statement

Former Member
0 Likes
511

Hi All

I have writen a SQL statement.

However, the result has duplicate value, may I know how should i optimize the code below to avoild duplicate? Or maybe a better way to do the query?

SELECT KKUNNR KVKORG KVTWEG BBZIRK

INTO CORRESPONDING FIELDS OF TABLE IT_REP

FROM VBPA AS V

INNER JOIN VBKD AS B ON ( BVBELN = VVBELN

AND BPOSNR = VPOSNR )

INNER JOIN VBAK AS K ON KVBELN = BVBELN

WHERE K~KUNNR IN S_REP

AND V~PARVW IN ('ZD','ZS','ZX').

Result I get :

300027 100 10 NBA

300027 100 10 NBA (DUPLICATE)

300027 100 10 NBA (DUPLICATE)

300005 187 10 NAE

Thanks a lot.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
466

Hi Hui ,

What i would suggest is keep the code as it is and once you have selected the data , use the command

DELETE ADJACENT DUPLICATES FROM IT_REP.

Regards

Arun

  • Assign points if reply is helpful

4 REPLIES 4
Read only

Former Member
0 Likes
466

use <b>delete adjacent duplicates</b> statement to avod duplicte entries ..


DELETE ADJACENT DUPLICATES FROM IT_REP Comparing kunnr vkorg.

Read only

Former Member
0 Likes
466

You could do a SELECT DISTINCT.

What you need to do is run an SE16 on the tables and see which table has the multiple entries. Then adjust your code accordingly to use the correct join conditions.

Extract the partner funtion into your table, this is probably causing the duplicate entries.

Message was edited by:

Martin Shinks

Read only

Former Member
0 Likes
467

Hi Hui ,

What i would suggest is keep the code as it is and once you have selected the data , use the command

DELETE ADJACENT DUPLICATES FROM IT_REP.

Regards

Arun

  • Assign points if reply is helpful

Read only

Former Member
0 Likes
466

Problem solved. Thanks everyone.