|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
Heh, gotta hate when something like that happens. Glad you're all fixed up.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > seemingly simple JOIN query - 3 tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|