Hello..
I need to query out most demanded products from my database... i have order table(order id, date, ...), orderitem table(order id, product id and quantity), and product table.. i don't understand how to write a query for this.. can someone kindly help me?
Virangya
0
Junior Poster
Recommended Answers
Jump to PostWouldn't that be the orderitem table, where you sum the quantities for each distinct product, and order that descending ?
Something like this perhaps, I have no relevant table to test with:
SELECT productid,SUM(quantity) AS total FROM orderitemtable GROUP BY productid ORDER BY total DESC
Jump to PostWhat other items ? You mean the other in the result ? If you run the query in phpMyadmin you get more results I suppose. Probably an error in your php code. I'd need to see it to be sure.
All 6 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Virangya
0
Junior Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Virangya
0
Junior Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Virangya
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.