+ 1

last task in the "LIKE and MIN" section of the SQL course

There is a mistake in the last task, it lacks a "GROUP BY" clause. https://www.sololearn.com/post/783261/ https://www.sololearn.com/learn/SQL/1862/

26th Nov 2020, 1:27 PM
Евгений
Евгений - avatar
17 Antworten
+ 1
CHERIEF Houcine Abdelkader yes it is, I tried it in code simulator
26th Nov 2020, 1:31 PM
Евгений
Евгений - avatar
+ 1
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.
26th Nov 2020, 6:39 PM
Евгений
Евгений - avatar
0
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`
26th Nov 2020, 6:34 PM
Ipang
0
But which column will be used to group the results, 'name' column? Wait a minute, where did you run the query (simulator)?
26th Nov 2020, 6:49 PM
Ipang
0
Ipang in the SQL course there are code samples, and you can run them. I bet you didn't try the SQL course.
26th Nov 2020, 6:51 PM
Евгений
Евгений - avatar
0
Евгений 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.
26th Nov 2020, 7:11 PM
Ipang
0
Ipang can you point me to any of them? Maybe those were the ones with aggregate functions only?
26th Nov 2020, 7:20 PM
Евгений
Евгений - avatar
0
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/
26th Nov 2020, 7:34 PM
Ipang
0
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.
26th Nov 2020, 7:59 PM
Евгений
Евгений - avatar
0
Yes, that's why I said let's wait for others' opinion ...
26th Nov 2020, 8:02 PM
Ipang
0
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
26th Nov 2020, 8:26 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
or we could use HAVING clause
27th Nov 2020, 12:30 AM
Евгений
Евгений - avatar
0
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 : )
27th Nov 2020, 2:25 AM
Ipang
0
Ipang do you know how to report it? I found nothing, that is why this "question" and my post.
27th Nov 2020, 10:54 AM
Евгений
Евгений - avatar
0
Евгений 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 ...
27th Nov 2020, 11:09 AM
Ipang
0
Ipang Thanks for the tip. I've sent a message through the feedback form and to info@sololearn.com. Now I'm waiting for reply.
27th Nov 2020, 2:53 PM
Евгений
Евгений - avatar
0
Good job Евгений 👍
27th Nov 2020, 2:55 PM
Ipang