I have this sql table and rows defined in SQL Fiddle
In SUPPLIER_DETAILS table there is a field called IS_PAYABLE which will have values either null or ‘Y’.
If IS_PAYABLE='Y', there could be one or more records for each PRODUCT_REG with different PRODUCT_NO.
E.g. PRODUCT_REG = 'HP_C20' has two records with IS_PAYABLE='Y'.
HP_C20 FR-A GB-A128 Y
HP_C20 FR-A GB-A098 Y
What I would like to have is if IS_PAYABLE='Y' and if there are multiple records for one PRODUCT_REG, then I would want only either one of the record and I want all the records with IS_PAYABLE is null.
How can I achieve this? If I did not make my requirement understandable, I will explain further.
Any help is highly appreciable.
Thanks
SQLFIDDLE
In inner query I’ve ranked the products with the same product_reg.
In the outer query i’ve got only one product per product_reg(the first ranked) and all non payable products.