Is this a mysql statement that you are calling from php, phpmyadmin, or from the command line ?
I would first test your statement in phpmyadmin if you have access or the command line.
If it works fine in either or you don't have access to them I would guess that you are either timing out with your script or running out of memory.
One way to curb a time out is to set
set_time_limit();
http://us3.php.net/set_time_limit
modify this some where in your output loop.
Another test you can do is to flush your output buffer.
http://us3.php.net/ob-start
do this in your loop to see what is coming out as your are printing it to the page.
thats the best i can do with out some more info man.