Q&A about the site for science fiction and fantasy enthusiasts
WITH CombinedTags AS ( SELECT Users.Id as UserId, Users.DisplayName, Users.AboutMe, Users.Location, Tags.TagName FROM Comments INNER JOIN Posts ON Posts.Id = Comments.PostId INNER JOIN Posts AS PostsP ON PostsP.Id = Posts.ParentId INNER JOIN PostTags ON PostTags.PostId = PostsP.Id INNER JOIN Tags ON PostTags.TagId = Tags.Id INNER JOIN Users ON Users.Id = Comments.UserId WHERE Users.Location = 'Athens' UNION ALL SELECT Users.Id as UserId, Users.DisplayName, Users.AboutMe, Users.Location, Tags.TagName FROM Users INNER JOIN Posts ON Posts.OwnerUserId = Users.Id INNER JOIN PostTags ON PostTags.PostId = Posts.Id INNER JOIN Tags ON PostTags.TagId = Tags.Id WHERE Users.Location = 'Athens' ) SELECT UserId, STRING_AGG(CAST(TagName AS NVARCHAR(MAX)), ';') AS Tags FROM CombinedTags GROUP BY UserId ORDER BY Tags ASC;