Home > database >  How to optimize the SQL query code, this period of ten seconds
How to optimize the SQL query code, this period of ten seconds

Time:09-30

//how to optimize the SQL query code, this period of ten seconds to
 


-- the product categoriesThe SELECT PK_ID ProdSortParentID, ProdSortName FROM dbo. ProductSort WHERE PK_ID IN (

, inquiring the product category ID is in the product category product ID
The SELECT ProdSortParentID FROM dbo. ProductSort WHERE PK_ID IN (

- inquiring the product category ID
The SELECT FK_ProductSortID FROM dbo. Shop_CompanyProductSort WHERE
FK_CompanyListID=6795 and
FK_ProductSortID IN (

- query classification of the company all product ID
The SELECT FK_ProductTypeID FROM Shop_ProductList WHERE FK_CompanyListID=6795 AND IsAudit=1 AND isDelete=0 GROUP BY FK_ProductTypeID
) GROUP BY FK_ProductSortID

) GROUP BY ProdSortParentID
)











CodePudding user response:

You remove the Group by, this words seriously affect performance,
If only query the existence of a certain value in another table and sub queries using the Select top 1... .

CodePudding user response:

Suggestion:
1. Instead of inner join writing.
2. The group by should be removed.
3. Note the query field, and associated fields should be indexed.
  • Related