Subject | need help on query optimisation |
---|---|
Author | Ben Johnson |
Post date | 2002-10-08T04:11:55Z |
Hi All,
I have two tables like this
account_heads
-------------
company_id
id
account_nm
PK - company_id + id
products
--------
company_id
id
product_nm
sale_p_id
tax_p_id
purchase_p_id
PK - company_id + id
There is FK also to company_id + *_p_id to account_heads on
company_id + id
Now when I send a query like this
SELECT products.id, products.product_nm, S.account_nm,
T.account_nm, P.account_nm
FROM products, account_heads S, account_heads T, account_heads
P
WHERE ( S.company_id = products.company_id )
AND ( S.id = products.sale_p_id )
AND ( T.company_id = products.company_id )
AND ( T.id = products.tax_p_id )
AND ( P.company_id = products.company_id )
AND ( P.id = products.purchase_p_id )
AND ( ( products.company_id = :dCID ) )
It is taking a lot of time. But if I remove the last line it is
lightning fast. I can't
go without that last line if I need to select only a company's
product. Pls help
Thank you.
Ben.
__________________________________________________________
Give your Company an email address like
ravi @ ravi-exports.com. Sign up for Rediffmail Pro today!
Know more. http://www.rediffmailpro.com/signup/
I have two tables like this
account_heads
-------------
company_id
id
account_nm
PK - company_id + id
products
--------
company_id
id
product_nm
sale_p_id
tax_p_id
purchase_p_id
PK - company_id + id
There is FK also to company_id + *_p_id to account_heads on
company_id + id
Now when I send a query like this
SELECT products.id, products.product_nm, S.account_nm,
T.account_nm, P.account_nm
FROM products, account_heads S, account_heads T, account_heads
P
WHERE ( S.company_id = products.company_id )
AND ( S.id = products.sale_p_id )
AND ( T.company_id = products.company_id )
AND ( T.id = products.tax_p_id )
AND ( P.company_id = products.company_id )
AND ( P.id = products.purchase_p_id )
AND ( ( products.company_id = :dCID ) )
It is taking a lot of time. But if I remove the last line it is
lightning fast. I can't
go without that last line if I need to select only a company's
product. Pls help
Thank you.
Ben.
__________________________________________________________
Give your Company an email address like
ravi @ ravi-exports.com. Sign up for Rediffmail Pro today!
Know more. http://www.rediffmailpro.com/signup/