Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
steve48
Starting Member
6 Posts |
Posted - 2010-04-09 : 10:59:10
|
| I have a PersonTable with PersonID, FirstName, Last Name, etcI have an OfferTable with BuyerID, AgentId, SellerID.I want to write a query to get the names of the Buyer, Agent, Seller from the PersonTable based on the corresponding IDs in the OfferTable. I have tried a bunch of different things but nothing worked. Any help will be appreciated.Steven Greenbaum |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-09 : 11:03:58
|
Like this:selectBuyer.LastName,Agent.LastName,Seller.LastNamefrom OfferTable ojoin PersonTable as Buyer on Buyer.PersonID = o.BuyerIDjoin PersonTable as Agent on Agent.PersonID = o.AgentIDjoin PersonTable as Seller on Seller.PersonID = o.SellerID No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-09 : 11:04:34
|
| Try this:Select B.FirstName as Buyer , A.FirstName as Agent, S.FirstName as Sellerfrom OfferTAble OT inner join PersonTable B on B.PersonId = OT.BuyerIdinner join PersonTable A on a.PersonId = OT.AgentIdinner join PersonTable s on s.PersonId = OT.SellerIDRegards,Bohra |
 |
|
|
steve48
Starting Member
6 Posts |
Posted - 2010-04-09 : 12:13:23
|
| Thank you for your quick reply, This workedSteven Greenbaum |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-09 : 12:54:44
|
Regards,I am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|
|
|
|