[posted and mailed, please reply in news]
Allan (proflicker@hotmail.com) writes:[color=blue]
> Select Product.ProdID, Colors.Colors
> From
> Products
> Left Join Colors
> on Product.ProdID = Colors.ProdID
> where Colors.Colors = "blue"[/color]
When you say:
FROM a LEFT JOIN b on ....
You are, concpetually, constructing a table. Then you apply a WHERE
clause to filter out rows from that table.
Thus for
Products Left Join Colors on Product.ProdID = Colors.ProdID
You get a table with data in all columns for Products, but where
there is no matching row in Colors, you get NULL.
Then you apply a WHERE clause to this, but then you filter all those
NULL rows, because NULL is not equal to "blue".
The remedy is to move the condition to the ON clause:
Products Left Join Colors
on Product.ProdID = Colors.ProdID
and Colors.Color = "blue"
Now the condition on Colors becomes part of that conceptual table.
--
Erland Sommarskog, SQL Server MVP,
esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp