Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hirani_prashant
Yak Posting Veteran
93 Posts |
Posted - 2008-05-28 : 02:12:29
|
| Hi,Mine Below Query takes considerable time at the time of execution.Can any one help me, what is the other way to write this query?Declare @p_Mkt_View_Id intSet @p_Mkt_View_Id = 17 Select Distinct Customer_id From Active_Product_Cust_DtlWhere Product_Group_Code in (Select Distinct Product_Group_Code From Products Where Product_code in ( select Distinct ProductId from pit where pitid in (select pitid from marketviewdef where mktviewid = @p_Mkt_View_Id)))ThanksPrashant |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-28 : 02:17:04
|
change like this & try:-Select Distinct Customer_id From Active_Product_Cust_Dtl ainner join Products pON a.Product_Group_Code=p.Product_Group_Code inner join pit pion pi.ProductId =p.Product_codeinner join marketviewdef mon m.pitid =pi.pitid where mktviewid = @p_Mkt_View_Id Also try putting indexes on joining columns and column in where clause. |
 |
|
|
raja_saminathan
Starting Member
12 Posts |
Posted - 2008-05-28 : 02:21:16
|
| Hi ,Try thisselect Distinct Customer_id from Active_Product_Cust_Dtl Ainner join Products p on A.Product_Group_Code = p.Product_Group_Code inner join pit on p.Products_Code = pit.ProductIdinner join marketviesdef M on M.pitid =pit.pitidwhere M.mktviewid=@P_Mkt_View_IdRajesh |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-05-28 : 02:25:29
|
| hi try this..SELECT DISTINCT Customer_id FROM Active_Product_Cust_Dtl A Left JOIN Product_code P ON A.Product_Group_Code = P.Product_Group_CodeLeft JOIN Products Pd ON P.ProductId = Pd.ProductIdLeft JOIN pit pt ON Pd.Product_code = pt.Product_codeLeft JOIN marketviewdef MK ON pt.pitid = Mk.pitidwhere MK.mktviewid = @p_Mkt_View_Id |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-28 : 04:00:55
|
quote: Originally posted by under2811 hi try this..SELECT DISTINCT Customer_id FROM Active_Product_Cust_Dtl A Left JOIN Product_code P ON A.Product_Group_Code = P.Product_Group_CodeLeft JOIN Products Pd ON P.ProductId = Pd.ProductIdLeft JOIN pit pt ON Pd.Product_code = pt.Product_codeLeft JOIN marketviewdef MK ON pt.pitid = Mk.pitidwhere MK.mktviewid = @p_Mkt_View_Id
No use of giving LEFT JOIN if you are leaving the WHERE condition as it is as it will again return only those records which have matching values in marketviewdef table. If you really wish to use LEFT JOIN to get results from first table regardless of matching condition on other tables you need to modify WHERE clause like thiswhere (MK.mktviewid = @p_Mkt_View_Id OR MK.mktviewid IS NULL) |
 |
|
|
|
|
|