I'm having a problem doing a mysql query.
I have two tables.
create table product (
productid integer,
productname varchar(20),
cost float,
primary key(productid)
)engine=innodb;
create table purchases (
purchaseid integer,
fproductid integer,
total integer,
primary key(purchaseid, fproductid),
foreign key(fproductid) references product(productid)
)engine=innodb;
What I want to get from these two tables is the top 10 most popular products purchased, and I want the product name, not the productid. So basically the names of the product id's that appears the most times in the 'purchases' table and how many times this product has been purchased.
select max(productname), productname
from product, purchases
where product.productid=purchase.fproductid
group by productid
limit 10;
This is what I've tried so far, but I'm not getting the correct values.
Thank you.