2226 Invalid usage of a subquery

Advantage Error Guide

Problem: A subquery was used in an invalid position in an SQL statement.

Solution: Use a temporary table to store the result of the subquery, then use the temporary table in place of the subquery in the original SQL statement or redesign the SQL statement to comply to the allowed usage of subqueries.