为什么这个MySQL查询不起作用

时间:2017-03-03 19:19:32

标签: mysql sql

select p_product 
from (select p_product, count(p_product) 
      from rental 
      group by p_product 
      order by count(p_product) desc LIMIT 5);
  

错误:每个派生表都必须有自己的别名

1 个答案:

答案 0 :(得分: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