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
 General SQL Server Forums
 New to SQL Server Programming
 Left Join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dolphin123
Yak Posting Veteran

USA
54 Posts

Posted - 02/08/2013 :  11:16:32  Show Profile  Reply with Quote
Hi,

Hope someone can help me. Should be straight forward. I am having a hard time understanding this:

The following query returns the right results as expected.

SELECT
S.companyname AS supplier, S.country,
P.productid, P.productname, P.unitprice
FROM Production.Suppliers AS S
LEFT JOIN Production.Products AS P
ON S.supplierid = P.supplierid
WHERE S.country = N'Japan';


The following query, which I thought should show me the same results as above does not. :(


SELECT
S.companyname AS supplier, S.country,
P.productid, P.productname, P.unitprice
FROM Production.Suppliers AS S
LEFT JOIN Production.Products AS P
ON S.supplierid = P.supplierid
and S.country = N'Japan';


can someone explain the behaviour, please?

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 02/08/2013 :  11:18:35  Show Profile  Reply with Quote
see

http://weblogs.sqlteam.com/jeffs/archive/2007/05/14/criteria-on-outer-joined-tables.aspx

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

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 02/08/2013 :  12:20:00  Show Profile  Reply with Quote
A description of the behavior in words might be stated this way:

The first query is telling SQL Server this:

"Give me those the rows from Suppliers where the country is Japan. And, oh, by the way, include a few columns (productid, productname etc) from the products table if these supplier ids are found in the products table."

The second query is telling SQL Server this:

"Give me all the rows from Suppliers. And, oh, by the way, include a few columns (productid, productname etc) from the products table if these supplier ids are found in the products table AND if the supplier is from Japan"
Go to Top of Page

dolphin123
Yak Posting Veteran

USA
54 Posts

Posted - 02/08/2013 :  22:29:33  Show Profile  Reply with Quote
Thanks a lot guys.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 02/08/2013 :  23:18:26  Show Profile  Reply with Quote
welcome

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

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.03 seconds. Powered By: Snitz Forums 2000