Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 20th, 2004, 12:27 PM
ericwright ericwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 ericwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
seemingly simple JOIN query - 3 tables

This seems like it should be simple, but I've been searched Google groups, this and other forums, and other online resources and I can't get this to work. Thanks in advance for any help.


There are three tables: Personnel (the main table), Departments, and Titles.

PERSONNEL
Code:
ID Name	DepartmentID TitleID Email 
1 John Doe 1	1 jdoe@example.com
2 Jane Smith 1 2 jsmith@example.com
3 John Roe 2 3 jroe@example.com




DEPARTMENTS
Code:
ID Department
1 Management
2 Developers



TITLES
Code:
ID Title_Long Title_Short
1 Chief Executive Officer CEO 
2 Chief Financial Officer CFO
3 Head Developer Head Developer




Given a certain name (say, "John Doe"), I want to return his personnel row with the real values subsituted for DepartmentID and TitleID (and only Title_Short for TitleID).

I have tried the following:

SELECT Name, Email, Department, Title_Short
FROM personnel, departments, titles
WHERE Name = "John Doe"
INNER JOIN departments ON personnel.DepartmentID = departments.ID
INNER JOIN titles ON personnel.TitleID = titles.ID


SELECT Name, Email, Department, Title_Short
FROM personnel, departments, titles
WHERE Name = "John Doe"
AND personnel.DepartmentID = departments.ID
AND personnel.TitleID = titles.ID



Both of these get errors.

I just want to input the person's name "John Doe", and get the whole personnel record, with all the foreign keys replaced with their real value.

I really appreciate and solutions or resources.

Eric

Reply With Quote
  #2  
Old July 20th, 2004, 02:45 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
What're the errors? The second one looks like it'd work with no problem.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old July 20th, 2004, 03:23 PM
ericwright ericwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 ericwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
aha!

The problem was, the example I posted works, but I had a mistake in the actual table/query.
Thank you very much for telling me that it SHOULD work. I went back through it, and made it work.

Thanks again.

Reply With Quote
  #4  
Old July 20th, 2004, 04:02 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Heh, gotta hate when something like that happens. Glad you're all fixed up.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > seemingly simple JOIN query - 3 tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT