Query matches what was ordered to fields in database

I need to:
        // check how many are in stock
        // if stock is zero ... say on back order
        // if stock is greater than zero subtract 1