I have a query that takes too long to execute. I need to know if there is any optimum way of executing that to reduce execution time.
my query is
SELECT TOP (2) ID,
(
SELECT SUM(CurrentStock) AS SimilarItemQuantity
FROM Inventory AS T1
WHERE (Inventory.ProductName = ProductName)
)
AS Expr1
FROM Inventory
Consider that for 20 records and it takes 15 seconds. Is there a more faster way of doing it.
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `Inventory` ADD INDEX `inventory_idx_productname` (`ProductName`);
SELECT
TOP (2) Inventory.ID,
(SELECT
SUM(T1.CurrentStock) AS SimilarItemQuantity
FROM
Inventory AS T1
WHERE
(
Inventory.ProductName = Inventory.ProductName
)) AS Expr1
FROM
Inventory