I know I have seen this solution before.....

  • But I can't seem to figure out this query.

    I have a table with columns ID as PK, PathwayID as int

    here is some sample data

    ID PathwayID

    1 1

    2 1

    3 1

    4 2

    5 2

    6 2

    I am trying to get all the ID's for the first instance of the pathwayID. My result set would be

    ID PathwayID

    1 1

    4 2

    I will keep trying on my end...thanks for any help

    markus

  • Select min(ID) as ID, PathwayID

    From YourTable

    Group By PathwayId

    Order By ID

  • arggggg

    That was way to simple compaired to the queries I was trying to compose.

    Thanks so much ron

    markus

  • Your welcome.   The other way would be to use a correlated sub query.

    Select ID, PathwayID

    From YourTable  as A

    Where ID = (Select min(ID)

                      From YourTable

                      Where PathwayId = A.PathwayId)

    Order By ID

  • Ron K's first solution is elegant and simple.

    I would make one small change in the Order By clause. 

    Select min(ID) as ID, PathwayID

    From #MyTable

    Group By PathwayId

    Order By PathwayID, ID

    The original question implied that all records with 1 in PathwayID 1 would precede the records with 2 in the PathwayID (e.g. they would be ordered by PathwayID).

    This may not always be the case.

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply