SQL clause starting in the middle paragraph, while pressing the enter key

Screen Link:

My 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 5

What I expected to happen: I expected the code to run and bring out the required output, since I’m certain the code is correct.

What actually happened: It bring forth error, and i’m a little bit confused.

(sqlite3.OperationalError) near "5": syntax error
[SQL: 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 5]
(Background on this error at: http://sqlalche.me/e/e3q8)
I immediately i hit the enter button to start another clause, it starts from the middle of the paragraph, that giving me a little bit of issues.

I will appreciate, any community member to enlighten me please, Thanks.

Hey.

It is not, if for nothing else, you’re at least missing a closing parenthesis for the subquery.

Hey, Thanks for the reply,

look at this!
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 5)

correct right?

Thanks, it worked. Please, one more thing, is it normal for a new clause to start in the middle paragraph, while writing a script of codes?

I’m not sure what you mean with “new clause in the middle paragraph”. If you’re talking about the portion of code below, then that’s the whole point of this mission, it’s a subquery!

SELECT Major_category
  FROM recent_grads
 GROUP BY Major_category
 ORDER BY SUM(Total) DESC
 LIMIT 5;

Thanks for the help, really appreciate.

1 Like