Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am trying to find the sql query to get the red boxed items from the diagram. What is the query to get the red boxed columns?

enter image description here

I have been trying to the sql query for the columns in the red box, any assistance would be helpful.

I tried this query:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT

Employees.LastName,

Employees.FirstName,

Region.RegionDescription

FROM

    (
    
        (
    
            (Employees 
    
                LEFT JOIN
    
                EmployeeTerritories 
    
                    ON Employees.EmployeeID = EmployeeTerritories.EmployeeID) 
    
        LEFT JOIN
    
        Territories 
    
            ON EmployeeTerritories.EmployeeID = Territories.TerritoryID) 
    
    LEFT JOIN
    
      Region 
    
        ON Territories.RegionID = Region.RegionID
    
    ); 

>Solution :

Your join with Territories was on EmployeeID (EmployeeTerritories.EmployeeID = Territories.TerritoryID), but should be on EmployeeTerritories.TerritoryID = Territories.TerritoryID. And removed all the brackets, makes it easier to read. Does this work for you?

SELECT
  Employees.LastName,
  Employees.FirstName,
  Region.RegionDescription
FROM Employees 
LEFT JOIN EmployeeTerritories 
ON Employees.EmployeeID = EmployeeTerritories.EmployeeID
LEFT JOIN Territories 
ON EmployeeTerritories.TerritoryID = Territories.TerritoryID
LEFT JOIN Region 
ON Territories.RegionID = Region.RegionID
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading