Retrieving the Top 5 Items from Each Category in MySQL
Encountering the error "Subquery returns more than 1 row" while trying to fetch the top five menu items for each menu category? The solution resides in employing side effecting variables.
Let's break down the revised approach:
In the subquery, we introduce side effecting variables @r and @g using SQL's @ notation. These variables are used to track group membership and increment the rank within each group.
By implementing this approach, you can efficiently obtain the desired results without the "Subquery returns more than 1 row" error.
The above is the detailed content of How to Retrieve the Top 5 Items from Each Category in MySQL While Avoiding the 'Subquery Returns More Than 1 Row' Error?. For more information, please follow other related articles on the PHP Chinese website!