Thanks biswas,
But i am using joins. how can i use this logic with joins

Thanks