I have a table that contains the following columns:
ProductID, ProductName, Price, CategoryID.
The goal is to print all the details (ProductID, ProductName, Price, and Category) about the most expensive product.
I executed the following query:
str = "SELECT ProductID, ProductName, MAX(Price) AS MaxPrice, CategoryID FROM Products;";
However, the exception mentioned in the title appears, and I do not find a reason for the exception appearance. I searched for explanations on the following links:
I have also read and practiced in SQL Lesson 10: Queries with aggregates (Pt. 1)
According to my checking in SQLBolt, the way I wrote the query is acceptable.
After reading and practicing, I still do not understand why I need to use the GROUP BY here. It’s not that I need to present the maximum price of each group…
Thank you very much beforehand!