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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Inner Join <> problem

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2012-12-18 : 18:55:39
Hi All,


I'm struggling with this query:

SELECT TOP (100) PERCENT dbo.T_Product_Main.CategoryID, dbo.T_Order_Main.CustomerID, dbo.V_Top20_30days.ProductID,
dbo.T_Order_Detail.ProductID AS customerproductid
FROM dbo.T_Order_Main INNER JOIN
dbo.T_Order_Detail ON dbo.T_Order_Main.ORDERID = dbo.T_Order_Detail.OrderID INNER JOIN
dbo.T_Product_Main ON dbo.T_Order_Detail.ProductID = dbo.T_Product_Main.id INNER JOIN
dbo.V_Top20_30days ON dbo.T_Product_Main.CategoryID = dbo.V_Top20_30days.CategoryID AND
dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductID
WHERE (dbo.T_Order_Main.CustomerID = 226869)
GROUP BY dbo.T_Product_Main.CategoryID, dbo.T_Order_Main.CustomerID, dbo.V_Top20_30days.ProductID, dbo.T_Order_Detail.ProductID

i'm trying that dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductID

It only show productid that are V_Top20_30days and not in T_Order_Detail

doesn't seem to work, i get these results , as you can see product 355 should be there because it is in both
Categoryid customerid productid customerproductid
1024 226869 355 2422
1024 226869 416 355
1024 226869 416 2422
1063 226869 421 2027
1011 226869 494 2720
1024 226869 521 355

any help, thanks a lot

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-19 : 00:37:30
Replace this part (AND dbo.T_Order_Detail.ProductID <> dbo.V_Top20_30days.ProductID) with the following:

AND dbo.V_Top20_30days.ProductID NOT IN (SELECT distinct ProductID FROM dbo.T_Order_Detail WHERE Product_id IS NOT NULL)

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-19 : 03:33:17
make sure you read this

http://www.sqlservercentral.com/articles/T-SQL/61539/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2012-12-19 : 04:24:51
mmm that doesn't produce any result
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-19 : 04:32:40
quote:
Originally posted by mike13

mmm that doesn't produce any result


Post your complete query once

--
Chandu
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2012-12-19 : 04:41:29
cannot see what that has todo with my select

quote:
Originally posted by visakh16

make sure you read this

http://www.sqlservercentral.com/articles/T-SQL/61539/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-19 : 05:01:15
quote:
Originally posted by mike13

cannot see what that has todo with my select

quote:
Originally posted by visakh16

make sure you read this

http://www.sqlservercentral.com/articles/T-SQL/61539/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






Check the <> condition on JOIN

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gtopawb
Starting Member

5 Posts

Posted - 2012-12-27 : 02:16:17
unspammed
Go to Top of Page
   

- Advertisement -