%%% First get minimum onHand using the same query as before % Get two copies of the onHand column tOnHand := project onHand(part); tOnHandCopy(onHand1) := tOnHand; % Cross product the two copies of onHand and find all values that are NOT the min onHandNotMin := project onHand (select onHand > onHand1 (tOnHand product tOnHandCopy)); % Get the differnce to be left with only the minimum onHandMin := tOnHand difference onHandNotMin; % Get parts that are minimum (the 'hot list') minimumPartNum := project partNum (onHandMin njoin part); % Get all orderNums and partNums orderNums := project orderNum, partNum (orderLine); % Get all orderNums orderLineOrderNum := project orderNum (orderNums); % Cross multiply all orderNums with all of the minimum onHand parts for expected, then get the difference between the actual orders. Left with NOT what you are looking for outOrderNum := project orderNum ((orderLineOrderNum product minimumPartNum) difference orderNums); % Get what you are NOT looking for a remove it from the list of ALL orders answer := orderLineOrderNum difference outOrderNum;