• Why don't you just delete this part from the second query, it is always true:

    and (avg_cost <> 0 OR avg_cost = 0)

    and (in_stock <> 0 OR in_stock = 0)