You need a second set to UNION on. The while loop doesn't hold on to the selected set and know it the next time through. What you're trying to accomplish is basically select all the data from mytable then union it again on the same set...n times. Which really doesn't make sense. Remember that SQL is set based, so select * From mytable will select every record in there. You also never state what you're trying to accomplish.