Misuse of aggregate function MAX()

Hello all! I have been working on the mission 368, Guided project for RSQLite, but even with the solutions from dataquest my code does not work. One example: q3 = “SELECT * FROM facts WHERE (population == MAX(population))”
result3 = dbGetQuery(conn, q3)
The error that appears: Error in result_create([email protected], statement) : misuse of aggregate function MAX()
Anyone who had the same experience or has a solution?

You cannot use aggregate functions in a WHERE expression.
You can use a subquery to do this, then your query will look like this
q3 = “SELECT * FROM facts WHERE population = (SELECT MAX(population) FROM facts)”

2 Likes

Oh, true! Thank you!