Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If MySQL is version 8, then he learned in window functions, so you can do this:
WITH tmp AS (SELECT department.name as department_name, employee.name, ROW_NUMBER() OVER (PARTITION BY department_id) AS rownum
FROM employee LEFT JOIN department
ON employee.department_id = department.id)
SELECT * FROM tmp
WHERE rownum <= 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question