The heaviest part in your query is the SELECT:
Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer
Where UserID Between 1 and 5000
and CustomerID in (Select CustId from Cust_Details Where CustName like 'Mi%')
The nested query probably is repeated for each row. You can check this running EXPLAIN PLAN
+ all the SELECT query. I guess the 'like' operator is used against a non-indexed column. In this case (like 'xyz%'
) a simple index can improve performance a lot.
[Added: moreover, SELECT CustId ... must output id's that are greater than 5000, that aren't needed at all. A composite index (CustId, CustName) on Cust_Details must also be useful.]
Try usign a join instead:
Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer c, Cust_Details cd
Where c.UserID Between 1 and 5000
and c.CustomerID=cd.CustId
and left(cd.CustName) = 'Mi'