Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2008 > SQL Server 2008
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 9th, 2010, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old April 9th, 2010, 11:30 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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."
===============================================
Reply With Quote
  #3 (permalink)  
Old April 9th, 2010, 12:15 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Yes that works

Thank you for fast response. Very helpful
Reply With Quote
  #4 (permalink)  
Old April 9th, 2010, 12:18 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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."
===============================================
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:33 PM.


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