I can’t find some pretty solution which would work for this, you can only create loop in loop which will compare row with other rows but this will be slower.
Also you can check this forum topic about this, I don’t know if it is a slolution for your problem.