Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2013
    Posts
    1

    Unanswered: HELP! Need to add another join to Query

    I think I'm in over my head, but here it goes:

    I am trying to run a query for employees that work in one location, however work for different companies within the corporation. Don and Kim work in the same building; but, Don works for corporate and Kim works for the local company.

    I have three tables:

    Contacts
    Id fname Department PhysicalLocation
    1 Don 1 2
    2 Kim 2 2

    ActualDepartments
    Id Company
    1 1
    2 2

    Company
    Id CompanyName Address
    1 Company1 101 Drive Dr
    2 Company2 202 Road Rd

    Query:

    SELECT fname,
    Bus.company,
    Phys.address
    FROM dbo.contacts
    INNER JOIN dbo.actualdepartments AS Bus
    ON contacts.department = Bus.id
    INNER JOIN dbo.company AS Phys
    ON contacts.physicallocation = Phys.id
    WHERE physicallocation = 2


    Don 1 202 Road Rd
    Kim 2 202 Road Rd

    I need to add an additional join to my first inner join so that I can pull the corresponding company name from the Company Id in the company table. I know I need to add something to the effect of:

    join dbo.ActualDepartments.Company = dbo.Company.Id

    So My results will have three columns: Name, Employer, Address

    Thanks in advance!

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Please post DDLs(create table statements, etc) and more sample data.

    For example:
    Values of Id and Company in ActualDepartments table are same, so why need two columns.

    And, please post expected result from your sample data.

Posting Permissions

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