Joining 3 tables in SQL Server

Results 1 to 2 of 2

Thread: Joining 3 tables in SQL Server

  1. #1
    Join Date
    Dec 1969

    Default Joining 3 tables in SQL Server

    i have 4 sets of 2 or 3 sql statements that each need to be combined into a single sql statement, so that i will have 4 sql statements instead of my current 8 or 10 statements. the database i am using is sql server.<BR><BR>my question is about how to rewrite the syntax to accommodate TWO JOINS in the resulting sql statement instead of the current 1 join per statement.<BR><BR>i am enclosing one of the sets of 2 sql statements that need to be combined. can someone please show me how these should look when they are distilled into a single statement? i will then follow this example for combining the other statements i will need to write that i am not including below.<BR><BR>the two that i would like help combining are:<BR>-----------------------------------------------------------------<BR>"SELECT Locations.CenterID, Locations.CenterName, Locations.CenterCity, TraditionSummary.CenterID " & _<BR>"FROM Locations LEFT OUTER JOIN TraditionSummary ON Locations.CenterID=TraditionSummary.CenterID " & _<BR>"WHERE CenterStatus = &#039;" & CenterStatus & "&#039;" & _<BR>"AND CenterCity= &#039;" & CenterCity & "&#039;" & _<BR>"ORDER BY CenterCity ASC"<BR><BR>"SELECT DISTINCT Locations.CenterID, Locations.CenterName, Locations.CenterCity, TeacherTraining.CenterID " & _<BR>"FROM Locations INNER JOIN TeacherTraining ON Locations.CenterID=TeacherTraining.CenterID " & _<BR>"WHERE CenterStatus = &#039;" & CenterStatus & "&#039;" & _<BR>"ORDER BY CenterCity ASC"<BR>-----------------------------------------------------------------<BR>what would these two look like as a single statement? i want ALL conditions to be met, not ANY condition. that is to say, i want the results to be more restrictive rather than less restrictive.

  2. #2
    Join Date
    Dec 1969

    Default RE: Joining 3 tables in SQL Server

    I think this is what you want to do.<BR>(Locations INNER JOIN TeacherTraining ON Locations.CenterID = TeacherTraining.CenterID) INNER JOIN TraditionSummary ON Locations.CenterID = TraditionSummary.CenterID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts