Click to See Complete Forum and Search --> : MySQL error: Every derived table must have its own alias


bubu
April 13th, 2007, 08:01 AM
hi.. Plz i need this urgently for my job. This query is already aliased and it stills gives the error:

Every derived table must have its own alias


SELECT num, nome FROM
(SELECT 0 as num, tema as nome FROM pesquisa AS t1)
LEFT JOIN
(SELECT COUNT(id) as num, tema as nome FROM pesquisa WHERE (YEAR(ano_defesa) = 0 OR 1=1) GROUP BY tema AS t2))

hspc
April 13th, 2007, 08:39 AM
Hi
try to change the query to:
SELECT num, nome FROM
(SELECT 0 as num, tema as nome FROM pesquisa) AS t1
LEFT JOIN
(SELECT COUNT(id) as num, tema as nome FROM pesquisa WHERE (YEAR(ano_defesa) = 0 OR 1=1) GROUP BY tema) As t2
On t1.num=t2.num

Note that the alias is outside the () and you must add a join condition.

bubu
April 15th, 2007, 07:40 AM
Thankyou! I will test it as soon as I arrive work!