I have a sub query question on VBAP & VBEP.I want to get a unique record for my sub query based on the below criteria.
Appreciate any help on sql subquery.
1) Sort the data by VBELN,POSNR ASC & Confirmed Qty ( VBEP-BMENG) DESC.
2) Now read only the first record for each Sales Order / Item. The result should extract ONLY one record from VBEP table.
Sample Data -1
VBAP Data
Sales Order Item
320910685 10600
VBEP Data
Sales Order Item Schedule Line Delivery Date Confirmed Qty
320910685 10600 1 10/21/2014 0
320910685 10600 3 10/21/2014 0
320910685 10600 6 10/21/2014 0
320910685 10600 7 11/03/2014 100
320910685 10600 8 11/03/2014 20
320910685 10600 9 11/03/2014 30
RESULT:
Sales Order Item Schedule Line Delivery Date Confirmed Qty
320910685 10600 7 11/03/2014 100
VBAP Data
Sales Order Item
320910685 11800
VBEP Data
Sales Order Item Schedule Line Delivery Date Confirmed Qty
320910685 11800 2 12/30/2015 1
320910685 11800 3 12/30/2015 1
RESULT:
Sales Order Item Schedule Line Delivery Date Confirmed Qty
320910685 10600 2 12/30/2015 1
[ OR ]
320910685 10600 3 12/30/2015 1