May 26, 2005 at 9:53 am
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
May 26, 2005 at 10:03 am
Select min(ID) as ID, PathwayID
From YourTable
Group By PathwayId
Order By ID
May 26, 2005 at 10:17 am
arggggg
That was way to simple compaired to the queries I was trying to compose.
Thanks so much ron
markus
May 26, 2005 at 10:42 am
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
May 27, 2005 at 7:34 am
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