SQL Code Error - Placement of FROM Statement

Screen Link:
Practice Problems For Scalar Subqueries In SQL | Dataquest

My Code:

  SELECT *  WHERE math_score > (SELECT AVG(math_score) FROM performance)
  FROM performance ; 

What I expected to happen: Run successfully

What actually happened:

OperationalError: near "FROM": syntax error

DQ’s answer is below. It varies from my answer only with respect to the placement of FROM statement in the outer query. Please help if there is a logic behind the way it is written !

FROM performance
WHERE math_score > (SELECT AVG(math_score)
FROM performance);

You are getting this error due to an error in syntax; SELECT and FROM must be defined before filtering your results with WHERE. Check out this short article that shows the difference between how we write our query and how SQL reads/executes it.

1 Like

thank you. it is part of missions, but i forgot!