I'd take a look through here. There are two methods highlighted in this thread. The one produced by Tom works well and works using a slightly hacked query. The one produced by me further down in the thread is a variant of this and can be produced without such a hack.