I need to select 8 people from a movie crew. I only want to have 3 producers and then let the query continue with other jobs.
This is my query now:
SELECT EmployeeID, j.NameEN, e.Firstname, e.Lastname, j.ID AS JobId
FROM crew AS c
LEFT JOIN job AS j ON c.JobID = j.ID
LEFT JOIN employee AS e ON c.EmployeeID = e.Id
WHERE c.MovieID = 237038
ORDER BY j.SortOrder ASC, c.JobID ASC, e.Score DESC
LIMIT 8
How can I achieve selecting only 3 employee's with the same job id?
Sample output
EmployeeID NameEN Firstname Lastname JobId
802 Director Chris Columbus 2
5707 Director David Yates 2
1705 Director Mike Newell 2
175 Director Alfonso Cuarón 2
5115 Writer Steve Kloves 3
2041 Writer Michael Goldenberg 3
11096 Writer J.K. Rowling 3
You can see here that I have 4 Directors. The desired output would be that there were 3 Directors max.