How do i write a sql statement where there is top5 and inner join?
Currently, this is what i have:
$query = "SELECT OrderItem.ProductCode , Product.ProductName,
count(OrderItem.OrderID) as total_orders
FROM `OrderItem`
GROUP BY ProductCode
ORDER BY total_orders DESC LIMIT 5
INNER JOIN Product ON Product.ProductCode = OrderItem.ProductCode";
but it’s not working.
tables:
Product table has columns:
ProductCode, ProductName, Cat, Qty, CostPr, RetailPr, VendorID
OrderItem table has columns:
OrderID, ProductCode, UnitPr, Qty,TotalPr
My objective is to display the productcode and productname of the top 5 products in orders submitted. Please help. thanks.
A
JOINis part of theFROMclause, and should come before yourGROUP BY: