SELECT DISTINCT serverId FROM MatchesList WHERE Id in (SELECT TOP 100 PERCENT matchId FROM MatchesPlayers WHERE name='Player0') ORDER BY COUNT(*)OVER(PARTITION BY serverId) DESC, serverId Such a request. There is a MatchesPlayers table where I want to select all matchId entries. Then I want to select all serverId from MatchesList so that I have a list of unique serverId sorted by their number. All is good, but the error
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.