CYBER WEEK - EXTRA SAVINGS EVENT
TRY A FREE LESSON

Subqueries SQL Part 4 question

Screen Link: https://app.dataquest.io/m/255/subqueries/4/returning-multiple-results-in-subqueries

Your Code: SELECT Major, Major_category FROM recent_grads
WHERE Major_category IN (SELECT Major_category FROM recent_grads GROUP BY Major_category ORDER BY SUM(Total) DESC LIMIT 10);

Can anyone explain to me what is happening here for in this query? Especially when we’re using GROUP BY Major_Category?

I’m going to modify the subquery by adding one column:

SELECT
    Major_category,
    SUM(Total) --I added this column
FROM recent_grads
GROUP BY Major_category
ORDER BY SUM(Total) DESC
LIMIT 10

Can you tell me what this query does? In the solution, it does exactly the same thing except the added column is not present.