I have a table with 3 columns in the format below:
WebcastChannelId, WebcastEventId, SortSequence
- 1 , 2 , 1
- 1 , 5 , 2
- 1 , 3 , 3
- 2 , 7 , 2
- 2 , 8 , 1
I would like to get the values for the webcastChannelId and WebcastEventId with the minimum sort sequence.
In the above example this would be:
WebcastChannelId, WebcastEventId, SortSequence
- 1 , 2 , 1
- 2 , 8 , 1
I have the following, which gets what I require, but I don't know if there is a more efficient way to do this?
SELECT wcwel.WebcastChannelId, wcwel.WebcastEventId
FROM [dbo].[WebcastChannelWebcastEventLink] wcwel with (nolock)
inner join [dbo].[WebcastChannelWebcastEventLink] wcwel1 with (nolock) on wcwel1.WebcastChannelId = wcwel.WebcastChannelId
group by
wcwel.WebcastChannelId,
wcwel.WebcastEventId,
wcwel.SortSequence
having
wcwel.SortSequence = MIN(wcwel1.SortSequence)