I’m trying to find unique User Id’s with and associated Media Id.
Here is what I have:
Select UserId, (Select Top(1) MediaId From Media Where UserId = M.UserId ORder By NewId()) as MediaId From Media as M Group By UserId
I tried different group by combinations, but none of them worked.
Is there a better way to do this?
Edit
The table looks like this:
MediaId int PK
UserId int FK
Status nvarchar(50)
Expected results
UserId MediaId
9 101
10 234
I think you have to consider a two step process i.e. creation of a work table that would have the unique userid and a column for the mediaid. You can then use a loop to set the top mediaid for each user.