Skip to content
Advertisement

Combining two sql queries into one to get most popular questions & answers in single table from SEDE

I have a query to get the most popular questions from the SEDE by

I have an additional query to get the highest scoring answer given a question id:

How can I combine these queries such that the ##QuestionId## from the second query is sourced from the Posts.Id from the first query, and the resulting HighestScoringAnswer column is added to the results of the first query? I tried using the Union operation but could not figure out how to “pass” the Id from one query to the other.

Advertisement

Answer

You have to make a JOIN between both queries (questions and answers); not an UNION (an UNION return the rows from the first query plus the rows from second query, excluding duplicated rows; but you want the top ten questions and more scored answer for each one in the same row).

Try this query, I think this is the query you are looking for:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement