SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Inner Join <> problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
215 Posts

Posted - 12/18/2012 :  18:55:39  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 12/19/2012 :  00:37:30  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 12/19/2012 :  03:33:17  Show Profile  Reply with Quote
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

Netherlands
215 Posts

Posted - 12/19/2012 :  04:24:51  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
mmm that doesn't produce any result
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 12/19/2012 :  04:32:40  Show Profile  Reply with Quote
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

Netherlands
215 Posts

Posted - 12/19/2012 :  04:41:29  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote
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

India
52325 Posts

Posted - 12/19/2012 :  05:01:15  Show Profile  Reply with Quote
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 - 12/27/2012 :  02:16:17  Show Profile  Reply with Quote
unspammed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000