Query join of table duplicates records

Posted on 2008-11-06
Last Modified: 2012-05-05
Adding the following join duplicates every record doubling the number of records in the below complicated query.  Any ideas to resolve this? I tried DISTINCTROW and changing the Inner Join to a Left Join.

INNER JOIN tblPatientProviderList ON [Complaint List].ComplaintID = tblPatientProviderList.ComplaintID) ON ReferDr.ContactID = tblPatientProviderList.ContactID)

      [Ins2Info.CompanyName]),6) & Format([Provider],
      '00') & [Last Name] & [Visit.ComplaintID] & [Ledger.Status] AS GroupField,
      [CPT code list].CPTCode,
      [Complaint List].MVA,
      [Complaint List].MVAState,
      [Complaint List].WC,
      [Complaint List].OtherAccident,
      IIf([Ins1GroupInfo.Group Number]='None',' ',
      [Ins1GroupInfo.Group Number]) AS Group1Number,
      IIf([Ins2GroupInfo.Group Number]='None',' ',
      [Ins2GroupInfo.Group Number]) AS Group2Number,
      [Patient Information].State,
      [Patient Information].[Postal Code],
      [Patient Information].Sex,
      [Patient Information].[Home Phone],
      [Patient Information].Birthdate,
      [Patient Information].[Last Name],
      [Patient Information].[First Name],
      [Patient Information].[Middle Initial],
      [Patient Information].Address,
      [Patient Information].City,
      [Patient Information].[Marital Status],
      [Patient Information].Employer,
      Provider.UPIN AS ProvUPIN,
      [Resource List].Initials,
      [Resource List].ProviderType,
      [Complaint List].PlaceOfService,
      [Complaint List].TypeOfService,
      IIf([PlaceOfService]>'20' AND
      '') AS AdmDate,
      IIf([PlaceOfService]>'20' AND
      '') AS LastDate,
      (((Contacts AS ReferDr
      INNER JOIN ((([Patient Information]
      INNER JOIN (((((Ledger
      LEFT JOIN [CPT code list] ON Ledger.CPTID = [CPT code list].CPTID)
      INNER JOIN ((((([Complaint List]
      LEFT JOIN [Insurance Group Information] AS Ins1GroupInfo ON [Complaint List].Group1 = Ins1GroupInfo.GroupID)
      LEFT JOIN [Insurance Group Information] AS Ins2GroupInfo ON [Complaint List].Group2 = Ins2GroupInfo.GroupID)
      LEFT JOIN [Insurance Patient Information] AS Ins1PatientInfo ON [Complaint List].Ins1PTID = Ins1PatientInfo.InsPTID)
      LEFT JOIN [Insurance Patient Information] AS Ins2PatientInfo ON [Complaint List].Ins2PTID = Ins2PatientInfo.InsPTID)
      INNER JOIN Visit ON [Complaint List].ComplaintID = Visit.ComplaintID) ON Ledger.VisitID = Visit.VisitID)
      LEFT JOIN [Insurance Companies] AS Ins1Info ON Visit.Ins1ID = Ins1Info.InsCoID)
      LEFT JOIN [Insurance Companies] AS Ins2Info ON Visit.Ins2ID = Ins2Info.InsCoID)
      LEFT JOIN (Contacts AS Provider
      RIGHT JOIN [Resource List] ON Provider.ContactID = [Resource List].ContactID) ON Visit.Provider = [Resource List].ResourceID) ON [Patient Information].PatientID = Visit.PatientID)
      LEFT JOIN Contacts AS Facility ON [Complaint List].Facility = Facility.ContactID)
      INNER JOIN tblPatientProviderList ON [Complaint List].ComplaintID = tblPatientProviderList.ComplaintID) ON ReferDr.ContactID = tblPatientProviderList.ContactID)
      INNER JOIN tblProviderDescription ON [Complaint List].ComplaintType = tblProviderDescription.BillingProviderType)
      INNER JOIN tblPatientProviderList AS tblPatientProviderList_1 ON (tblProviderDescription.ProviderDescriptionID = tblPatientProviderList_1.DescriptionID) AND
      ([Complaint List].ComplaintID = tblPatientProviderList_1.ComplaintID))
      INNER JOIN Contacts AS BillingProvider ON tblPatientProviderList_1.ContactID = BillingProvider.ContactID
      (((Ledger.LedgerID) In (2647,
      6) & Format([Provider],
      '00') & [Last Name] & [Visit.ComplaintID] & [Ledger.Status];
Question by:thenelson
    LVL 77

    Accepted Solution

    Distinct looks at every field in your Select clause.
    Are you saying that you have duplicates of entire rows in your output - I suspect that's not what you mean.

    If you have 'duplicates' based on some of the fields then you have to look at the tabl(s) that are contributing multiple rows for the same duplicate values.  For each table of this type, you need to create a sub-query to select just the unique records you want . Then use the subqueries instead of the tables in your main query.
    LVL 39

    Author Comment

    I found the answer. I need to add "AND ((tblPatientProviderList.DescriptionID)=2)" to the Where clause since the added join added two different sets of valves and I only wanted one of them.

    Although I got the solution before reading your comment, I'm going to give you the points since your suggestion is right on and would have led me to the solution if I didn't find it myself.  Thanks for the reply.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now