2017-03-03 99 views
-1
select p_product 
from (select p_product, count(p_product) 
     from rental 
     group by p_product 
     order by count(p_product) desc LIMIT 5); 

Error: Every derived table must have its own alias为什么这个MySQL查询不会工作

+2

你需要给你的子 - 查询别名。 – Siyual

+0

您只需将错误消息放入SO的搜索字段即可找到答案。 – Barmar

回答

1

添加别名的子查询:

select p_product 
from (
    select p_product, 
     count(p_product) 
    from rental 
    group by p_product 
    order by count(p_product) desc LIMIT 5 
    ) t; 
------^ here 

而且,你不是真的需要一个子查询:

select p_product 
from rental 
group by p_product 
order by count(p_product) desc LIMIT 5 
+0

的确,我不需要这个子查询。我只是用一个例子来检查它是如何工作的。 谢谢。 – Manpreet

相关问题