Does the database you are working with support paging?

If yes you could probably execute your query in smaller pieces.

Cheers,
_