simple OUTER JOIN (I thought)

simple OUTER JOIN (I thought)

am 11.09.2007 16:38:36 von tescodiscolondon

Two tables:

Fruit
fruitID, fruitName

Basket
buyerID, fruitID

(ie. we can see which buyer has what fruit in their basket)

I simply want to display all available fruit and whether or not it's
in a specific persons' basket.

SELECT Fruit.fruitID, Fruit.fruitName, IsNull(buyerID, 0)
FROM Fruit INNER JOIN Basket ON Fruit.fruitID = Basket.fruitID
WHERE Basket.buyerID = 12

but this just gives me what's in buyer 12s' basket.

What am I doing wrong? Am I a basket case...

Re: simple OUTER JOIN (I thought)

am 11.09.2007 17:28:02 von tescodiscolondon

Ah yes, never put your criteria into a WHERE clause.

SELECT Fruit.fruitID, Fruit.fruitName, IsNull(buyerID, 0)
FROM Fruit INNER JOIN Basket ON Fruit.fruitID = Basket.fruitID AND
Basket.buyerID = 12

gives me what I wanted.

Forget this post.

On 11 Sep, 15:38, tescodiscolon...@googlemail.com wrote:
> Two tables:
>
> Fruit
> fruitID, fruitName
>
> Basket
> buyerID, fruitID
>
> (ie. we can see which buyer has what fruit in their basket)
>
> I simply want to display all available fruit and whether or not it's
> in a specific persons' basket.
>
> SELECT Fruit.fruitID, Fruit.fruitName, IsNull(buyerID, 0)
> FROM Fruit INNER JOIN Basket ON Fruit.fruitID = Basket.fruitID
> WHERE Basket.buyerID = 12
>
> but this just gives me what's in buyer 12s' basket.
>
> What am I doing wrong? Am I a basket case...

Re: simple OUTER JOIN (I thought)

am 13.09.2007 04:44:36 von Ed Murphy

tescodiscolondon@googlemail.com wrote:

> Ah yes, never put your criteria into a WHERE clause.
>
> SELECT Fruit.fruitID, Fruit.fruitName, IsNull(buyerID, 0)
> FROM Fruit INNER JOIN Basket ON Fruit.fruitID = Basket.fruitID AND
^^^^^ OUTER, surely?
> Basket.buyerID = 12
>
> gives me what I wanted.