I am trying to fetch data from stackexchange database. My query is:
select distinct top 50 U.Id, U.DisplayName, U.Reputation,
Tags = stuff( (SELECT ','+p2.Tags
FROM posts p2 join votes V on p2.id = V.PostId
where V.VoteTypeId=5 and V.UserId = U.id
order by p2.CreationDate DESC
FOR XML PATH, TYPE).value('.[1]','nvarchar(max)')
,1,1,'')
from Users U
order by U.Reputation DESC;
However, when I run the query on data.stackexchange.com, it shows an error saying:Execution Timeout Expired.
Is there any way that I can modify the query to optimize the execution time so that I can run this query successfully?