dbTalk Databases Forums  

simple OUTER JOIN (I thought)

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss simple OUTER JOIN (I thought) in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tescodiscolondon@googlemail.com
 
Posts: n/a

Default simple OUTER JOIN (I thought) - 09-11-2007 , 09:38 AM






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...


Reply With Quote
  #2  
Old   
tescodiscolondon@googlemail.com
 
Posts: n/a

Default Re: simple OUTER JOIN (I thought) - 09-11-2007 , 10:28 AM






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... (AT) googlemail (DOT) com wrote:
Quote:
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...



Reply With Quote
  #3  
Old   
Ed Murphy
 
Posts: n/a

Default Re: simple OUTER JOIN (I thought) - 09-12-2007 , 09:44 PM



tescodiscolondon (AT) googlemail (DOT) com wrote:

Quote:
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.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.