DEV Community

Manav Misra
Manav Misra

Posted on


How To Use DISTINCT With a Join?


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 

Top comments (0)

Here is a post you might want to check out:

Regex for lazy developers

regex for lazy devs

Sorry for the callout 😆