-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
  • 69,699
  • 7
  • 57
  • 89
Manpreet
  • 540
  • 5
  • 19

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
  • 37,207
  • 6
  • 50
  • 70
  • 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