error: #1248 - Every derived table must have its own alias
As the error says, in a MySql query you have to name every derived table.
Derived tables (often called subqueries) are result sets used as table sources in a query, like the one in the following example:
(SELECT MAX(id) FROM yourtable GROUP BY name)
and you have to give each derived table an alias:
(SELECT MAX(id) FROM yourtable GROUP BY name) AS max_id
(the AS clause is optional) and you can then use it, for example, this way:
SELECT yourtable.*
FROM
yourtable INNER JOIN
(SELECT MAX(id) max_id FROM yourtable GROUP BY name) max_ids
ON yourtable.id = max_ids.max_id