• I'd use ALZDBA's solution.

    If that doesn't make sense, give us an idea of what the conditions are and we can help (tables/cols)