• Hi

    I'm not sure if you need to do a join on the personel tale but you can use a rank function

    RANK ( ) OVER ( [ partition_by_clause ] order_by_clause ) to rank your result sets into some sort of temp table or CTE and query the your output from there

    so using your two tables Personel and Structure I have written this script against the structure table that should start you off but if you need to do a join it should be simple. let me know if this helps

    WITH Personel_Structure

    AS

    (

    SELECT [SID],MID, RANK() OVER(PARTITION BY [SID] ORDER BY MID ASC) AS POS

    FROM Structure

    WHERE [SID] = 3

    )

    SELECT [SID],MID

    FROM Personel_Structure

    ORDER BY POS ASC