MYSQL - COUNT performed on limited number of rows in a Joined table

22 views Asked by At

I'd like to join two tables (resources and empath_task_history) then count the number of categories ("safety_level" on a limited number of rows.

Below is what I've tried, but I'm getting the following error: "ERROR 1248 (42000): Every derived table must have its own alias"

SELECT safety_level,COUNT(*)
FROM (SELECT * FROM empath_tasks_history LIMIT 10)
LEFT OUTER JOIN resources 
ON resources.resource_oid = empath_tasks_history.item_oid
GROUP BY safety_level;

I'd appreciate your help. Thank you.

1

There are 1 answers

0
James Eaves On

So the final correct code was:

SELECT safety_level,COUNT(*)
FROM (SELECT * FROM empath_tasks_history LIMIT 10) a
LEFT OUTER JOIN resources 
ON resources.resource_oid = a.item_oid
GROUP BY safety_level;

Thank you Fabricator.