This is practice with the MySQL Employees DB. The diagram for it is here.
I want to know the top 10 salaries.salary
, by employees.gender
.
I have tried:
SELECT DISTINCT employees.emp_no, employees.first_name, employees.last_name, employees.gender, salaries.salary
FROM employees
JOIN salaries ON employees.emp_no = salaries.emp_no
ORDER BY salaries.salary DESC
LIMIT 10;
+--------+------------+-----------+--------+--------+
| emp_no | first_name | last_name | gender | salary |
+--------+------------+-----------+--------+--------+
| 43624 | Tokuyasu | Pesch | M | 158220 |
| 43624 | Tokuyasu | Pesch | M | 157821 |
| 254466 | Honesty | Mukaidono | M | 156286 |
| 47978 | Xiahua | Whitcomb | M | 155709 |
| 253939 | Sanjai | Luders | M | 155513 |
| 109334 | Tsutomu | Alameldin | M | 155377 |
| 109334 | Tsutomu | Alameldin | M | 155190 |
| 109334 | Tsutomu | Alameldin | M | 154888 |
| 109334 | Tsutomu | Alameldin | M | 154885 |
| 80823 | Willard | Baca | M | 154459 |
+--------+------------+-----------+--------+--------+
It's almost right, but what happened with my DISTINCT
? I don't want so see the same emp_no
in the table.