-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

Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98
Manpreet
  • 570
  • 5
  • 20

1 Answers1

1

Add an alias to the subquery:

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

Also, you dont really need a subquery:

select p_product
from rental
group by p_product
order by count(p_product) desc LIMIT 5
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
  • Exactly, I dont need a subquery for this. I was just checking how it works with an example. Thanks. – Manpreet Mar 03 '17 at 19:25