Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I query a M-M Relationship?

Status
Not open for further replies.

rvancleef

Programmer
Apr 8, 2003
34
0
0
US
Assuming 3 tables:
Division (DivCode, DivName)
Department (DeptCode, DivCode, DeptName)
Professor (FName, LName, DeptCode)

How do I write a query to return a listing or professors by Division? So far I can only write queries that return Departments based on Division or Professors based on Department.

Is this a circumstance where Cursors are required?

Please return and code snippets or References to online articles that are clear for an SQL Server newbie.

Thanks!!!

 
Sorry to bother. I answered my own question.

Use an Inner Join:
SELECT facstaff.FirstName, facstaff.LastName , Department.DivisionCode, Department.DeptCode
FROM facstaff
INNER JOIN Department ON Department.DeptCode = facstaff.Dept
WHERE Department.DivisionCode = 'NS'
ORDER BY LastName,FirstName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top