this would be so much easier in SQL...there are numerous examples on the site.. can you use SQL?
SuperMan