I was searching for this for more than 3 hours through all queries in stackoverflow. This worked actually. is there any other smarter way to do this?