I have two tables that I want to query, one is Products, the other is Stats. I want to display product information for the most popular products (like a top ten). I wrote a query using a simple join which works, but its not returning the correct data and it takes a long time.
Tables:
products
p_name | img
stats
s_name | popularity
here's my query:
"SELECT products.img,stats.s_name
FROM products,stats
WHERE products.p_name = stats.s_name
ORDER BY stats.popularity DESC
LIMIT 0,10";
Like I said, the script works but the popularity rank is wrong and I think it's "joining" the whole product catalog before returning results which makes it slow.
Thanks in advance.