dbTalk Databases Forums  

sql question

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss sql question in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SPIDERMAN
 
Posts: n/a

Default sql question - 07-09-2003 , 02:59 PM






Hi gurus,

I have 3 tables as follows:
1) Buyers: BuyerID
2) Sellers: SellerID
3) BuyersSellers: BuyerID, SellerID, GoldorSilver

Where GoldorSilver contains either 'G' for Gold or 'S' for Silver.

The following query gives me all the buyers, which is what I want. But it
also give me duplicate rows if a buyer buy both Gold AND Silver. If I want
to reduce the number of rows (so that there aren't rows with similar
BuyerID) but add extra columns (Gold column and Silver column), how do I
write this query in Oracle SQL or ANSI99 SQL? Thank you in advance


select BuyerID, SellerID, GoldorSilver from Buyers, Sellers, BuyersSellers
where Buyers.BuyerID=BuyersSellers.BuyerID(+) and
Sellers.SellerID(+)=BuyersSellers.SellerID



Reply With Quote
  #2  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: sql question - 07-10-2003 , 10:55 AM






SPIDERMAN wrote:

Quote:
Hi gurus,

I have 3 tables as follows:
1) Buyers: BuyerID
2) Sellers: SellerID
3) BuyersSellers: BuyerID, SellerID, GoldorSilver

Where GoldorSilver contains either 'G' for Gold or 'S' for Silver.

The following query gives me all the buyers, which is what I want. But it
also give me duplicate rows if a buyer buy both Gold AND Silver. If I want
to reduce the number of rows (so that there aren't rows with similar
BuyerID) but add extra columns (Gold column and Silver column), how do I
write this query in Oracle SQL or ANSI99 SQL? Thank you in advance

select BuyerID, SellerID, GoldorSilver from Buyers, Sellers, BuyersSellers
where Buyers.BuyerID=BuyersSellers.BuyerID(+) and
Sellers.SellerID(+)=BuyersSellers.SellerID
Hint:
UNION ALL
DECODE

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)




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.