Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

codeigniter 3 get best-selling products

#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 by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #codeigniter #products
ADD COMMENT
Topic
Name
8+2 =