TOP per 'level' retrieval

Posts   
 
    
hitchhiker
User
Posts: 48
Joined: 20-May-2009
# Posted on: 27-Jun-2011 20:44:27   

Hi, Using 3.1, self-s. I wonder if anybody can put me on the right track?

Here's a table with some example data. Each row is linked to a 'parent' row, in tree fashion.

ID ...... ParentID

1 ...... 1 2 ...... 2 3 ...... 2 4 ...... 2 5 ...... 3 6 ...... 1 7 ...... 1 8 ...... 3 9 ...... 2 10...... 2

----------- Wanted results ------------

ID

1 6 7 2 3 4

I want to produce an efficient query that (among other things) can return x amount of rows from each level (with various sorts)..

In this case the first 3 from 'level 1', 2 from 'level 2'

Those parameters are variable - it may require 10 from level 1, first 3 from each of the next levels.

Cheers, Frank.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jun-2011 06:31:32   

Hi Frank,

Sorry but it's not clear what you are trying to achieve. Please show us a pseudo code or something clearer.

David Elizondo | LLBLGen Support Team
hitchhiker
User
Posts: 48
Joined: 20-May-2009
# Posted on: 29-Jun-2011 00:18:30   

Sorry about that - nvm, found a way now. Cheers, Frank.