User with the Most Favorites

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- User with the Most Favorites

select UserId, MAX(favcnt) as Favorites from 
(
    SELECT COUNT(*) AS favcnt, UserId
    FROM Votes 
      INNER JOIN 
        Users ON Votes.UserId = Users.Id
        WHERE Votes.VoteTypeId = 5
        GROUP BY UserId)
subq GROUP BY UserId

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results