Multiple tables with reddit

i’m wondering why this code:

WITH popular_post AS (
SELECT MAX(posts.score) AS ‘top_scorer’
FROM posts
GROUP BY posts.subreddit_id
)
SELECT *
FROM subreddits
JOIN popular_post
ON subreddits.id = posts.subreddit_id;
do not return the same result of the code suggested by the hint:
SELECT
posts.title,
subreddits.name AS ‘subreddit_name’,
MAX(posts.score) AS ‘highest_score’
FROM posts
INNER JOIN subreddits
ON posts.subreddit_id = subreddits.id
GROUP BY subreddits.id;

Could you either edit your answer or add a reply with your full query (part of it seems to have gone walkabouts :upside_down_face:). Ideally please format your code too as per the guidance linked below-

Struggling with this step, too. Are we supposed to save the results from the previous step? I’ve tried both and neither works.

The bottom have of your code is all you need. Remove everything before the third SELECT.

The question is asking to get the order the results by each popular post’s score in descending order. Using “Order by” instead of “group by”

I paste my code, hope this helps

WITH popular_posts AS (

SELECT *

FROM posts

WHERE score >= 5000

)

SELECT subreddits.name, popular_posts.title , popular_posts.score

FROM subreddits

INNER JOIN popular_posts

ON subreddits.id = popular_posts.subreddit_id

ORDER BY popular_posts.score DESC;

1 Like