Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in need to find the top employee in terms of sales but i am not able to get sufficient output

What I have tried:

select e_name from employee e join sale s on e.e_id=s.e_id group by sale_id limit 1;
Posted
Updated 25-Feb-19 23:03pm

You need to ORDER your query to bring the top value to the "top" - hint: in descending order.

Reference: MySQL :: MySQL 8.0 Reference Manual :: 8.2.1.14 ORDER BY Optimization[^]
 
Share this answer
 
Comments
Maciej Los 26-Feb-19 6:48am    
5ed!
Just to add to what CHill60 says: you need to ORDER BY sales, but since you are using GROUP BY, you will also need to look at an appropriate aggregate function.

Have a look here: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^] as that's the next thing that will bite you - it's SQL Server based but the principles are the same for MySql
 
Share this answer
 
Comments
Maciej Los 26-Feb-19 6:48am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900