Codeigniter 3 Get Best Selling Products

[Solved] Codeigniter 3 Get Best Selling Products | Php - Code Explorer | yomemimo.com
Question : codeigniter 3 get best-selling products

Answered by : annoying-anaconda-8kbjc3nrutmd

#You can use a SQL join between the tables on ProID, e.g.
select *
from products as p
inner join orderdetails as od on p.ProID = od.ProID
#You can use group by syntax to ensure you get distinct rows, e.g.
group by p.ProID
#Use aggregation function such as sum, count and avg to find out the totals in a select, e.g.
select sum(od.OrderQuantity) as total
#Use order by syntax to show the top answers, e.g.
order by sum(od.OrderQuantity) desc
#Use limit to show top n results, e.g.
limit 5
#Hopefully that gives you enough pointers to formulate the SQL yourself.
#notes, I've given the tables an alias to ensure you don't get conflicts between the column names. You can't reference total in your order statement due to the way SQL calculates the dataset. I've used an inner join, but you might want to look into left & right joins.

Source : https://stackoverflow.com/questions/20510628/how-can-i-query-this-sql-to-get-the-best-selling-product | Last Update : Thu, 23 Sep 21

Answers related to codeigniter 3 get best selling products

Code Explorer Popular Question For Php