Unfortunately, it would be hard to offer any meaningful suggestions without seeing the SQL statement you're using. Are you not able to share even the actual error message?
There are many things that can cause a query to run slowly.
If you are unable to post your query design, all any of us can do is make educated guesses based on previous experience.