/*ORDER 501999*/
UPDATE PRODUCT SET
PRODUCT.DEFAULTRETURNGRADE_ID=
(SELECT T.QUALITYGRADE_ID
  FROM QUALITYGRADE T
 WHERE T.PRIORITY = (SELECT MIN(Q.PRIORITY)
                       FROM QUALITYGRADE Q
                      WHERE Q.NEWGARMENT = 'N'
                        AND Q.DEFECTITEM = 'N'));