"lee" <lfairban_nospam (AT) amep (DOT) com> wrote
Quote:
I get what I think are strange results - I just don't understand why |
You just don't understand joins. When you join two tables, you can imagine
that they are multiplied together (this doesn't happen in practice, but it's
a good visualization) and that every row in the first table is matched with
every row in the second table. The join condition (ON ...) tells the DB
which rows to keep. So if you join where two fields are not equal, then you
will get every row in the first table matched to every row in the second
table EXCEPT the row where the field in table one and table two match.
www.sqlcourse.com www.sqlcourse2.com
Secondly, quit referencing your columns with anything more than the table
name. This isn't just non-standard, but Microsoft has indicated that four
part references (database.owner.table.column) will not work in the next
release of SQL Server (the one after 2005) and only two part references
(table.column) will be supported, so break the habit now.
You want an outer join, and you want to keep only the rows where the right
hand table had no match - that is, where there is no shipping information
for the product.
SELECT Products.ID AS ProductID, atblShipping.*
FROM dbo.Products
LEFT OUTER JOIN dbo.atblShipping ON Products.ID =
atblShipping.ShipKey
WHERE atblShipping.ShipKey IS NULL