17 AnswersNew Answer
CHERIEF Houcine Abdelkader yes it is, I tried it in code simulator
Ipang You miss the point. It's not about filtering or grouping. If you use aggregate function like MIN() in a field list, other fields have to be GROUP'ed.
It says "filtering by name and seller id", it did not say "grouped by name and seller id". * Filter of 'name' is done by using `LIKE` * Filter of 'seller_id' is done by using `IN`
But which column will be used to group the results, 'name' column? Wait a minute, where did you run the query (simulator)?
Ipang in the SQL course there are code samples, and you can run them. I bet you didn't try the SQL course.
Евгений Let's hear what others have to say. I can't say much here, cause I've also seen few examples of queries using MIN but without using GROUP BY.
Ipang can you point me to any of them? Maybe those were the ones with aggregate functions only?
Here is one, in the second example there's a use of MIN in a subquery without grouping in primary query. https://www.sqlservertutorial.net/sql-server-aggregate-functions/sql-server-min/
Ipang OK, I see. This query is not the same as the one I'm talking about. In your case in subquery there is aggregate function only in the column list. In short, one can't mix aggregate functions and not grouped columns.
Yes, that's why I said let's wait for others' opinion ...
I was sceptical, but after testing it I think you are right Евгений. I tested with this code on the employee table in the lesson that you linked. It should be equivalent to the code in the task: SELECT firstname, MIN(salary) FROM employees WHERE lastname LIKE '%s' AND id IN (4, 5, 6) Indeed it throws an error that firstname must be in groupby or aggregate function. Without MIN it works. And what should be the output anyway? For data of employees with lowest salary we would use MIN in a subquery for a WHERE clause and it would potentially return multiple entries whereas MIN returns a single value
or we could use HAVING clause
Wait a minute, guys, when I saw the screenshot above, it seems to be a query for a product, maybe it was supposed to find products with minimum cost (or rather price?), correct me if I'm wrong. So, is it actually about employees or products? I'm bit confused on the use of GROUP BY for this guys, if we were to find cheapest product then by right we should only have 1 result per product. So I'm kinda lost on why we need to group the rows by a column. I'm thinking grouping of rows is meant for a situation where multiple rows were expected for a certain grouped column (maybe I was misunderstanding). Note that I'm not questioning the concept of aggregates use with GROUP BY, rather the query itself. I think this *might* worth a report, so the quiz can be updated, if it was found to be faulty : )
Ipang do you know how to report it? I found nothing, that is why this "question" and my post.
Евгений I think either by in-app Feedback feature, or e-mail. Maybe it's by e-mail, cause I don't see this as bug report or suggestion. This is about one of the quizzes ...
Ipang Thanks for the tip. I've sent a message through the feedback form and to [email protected] Now I'm waiting for reply.
Good job Евгений 👍