FYI,
I figured out lots of things in my code.
I have created proper indexes in my tables which has reduced the execution time.
BTW,Isn't there a way to delete own post from the forum? Yesterday, somehow, I posted this topic in two forum which created some confusion.