2017-03-03 65 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