Gossamer Forum
Home : General : Databases and SQL :

More efficient SQL query?

Quote Reply
More efficient SQL query?
Can anyone see a more efficient SQL query to this beast below?

SELECT tblProducts.*, tblProductLookup.f32bit, (SELECT ProductURL FROM tblProductsSpecific WHERE ProductID = tblProducts.ID AND Site='32bit') AS ProductURL, (SELECT Count(*) FROM tblReviewLookup WHERE ProductID = tblProducts.ID) AS NumComments, (SELECT Company FROM tblLogins WHERE ID = tblProducts.Company) AS Company, (SELECT CompanyEmail FROM tblLogins WHERE ID = tblProducts.Company) AS CompanyEmail, (SELECT CompanyURL FROM tblLogins WHERE ID = tblProducts.Company) AS CompanyURL FROM tblProducts INNER JOIN tblProductLookup ON tblProducts.ID = tblProductLookup.ProductID WHERE tblProductLookup.CategoryID = 42 AND tblProducts.Enable = 1 order by tblProductlookup.f32bit DESC, tblProducts.title;


Basically I need the information from these tables, knowing just the CategoryID:
tblLogins - Company, CompanyEmail, CompanyURL
tblProducts - *, WHERE enable=1
tblReviewLookup - just a lookup table, I need to know how many reviews there are for the productid in question
tblProductLookup - contains ProductID, CategoryID and f32bit
tblProductsSpecific - I need to get the ProductURL of the the productid in question for the site '32bit'.