Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2008 > SQL Server 2008
|
SQL Server 2008 General discussion of SQL Server *2008* version only - not related to a specific book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2010, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Need help with simple query

I have a PersonTable with PersonID, FirstName, Last Name, etc

I 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.
 
Old April 9th, 2010, 11:30 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am not a SQL Guru so there might be something more effecient but it seems something like this would work:

SELECT
p1.LastName + ', ' + p1.FirstName as Buyer,
p2.LastName + ', ' + p2.FirstName as Agent,
p3.LastName + ', ' + p3.FirstName as Seller
FROM offer o
LEFT JOIN Person p1 on p1.PersonID = o.BuyerID
LEFT JOIN Person p2 on p2.PersonID = o.AgentID
LEFT JOIN Person p3 on p3.PersonID = o.SellerID

hth
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old April 9th, 2010, 12:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Yes that works

Thank you for fast response. Very helpful
 
Old April 9th, 2010, 12:18 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You are quite welcome. Gald it worked out for you!

-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Query help pls? Mitch_A SQL Language 5 February 3rd, 2006 05:13 PM
Simple Query Need Help ~Bean~ SQL Language 2 June 27th, 2005 11:22 AM
Simple query errors Justine Access 5 February 12th, 2004 09:43 AM
Simple Tomcat Query? Baztec Apache Tomcat 0 January 13th, 2004 11:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.