Solved

Unwanted cartesian results (a chronic problem for me!)

Posted on 2008-06-20
4
300 Views
Last Modified: 2013-12-25
I keep getting unwanted cartesian results in my join, no matter how long I work at this.  (Access SQL seems to give me a harder time than SQL Server.)

I want all records from the patient table and only one matching record each from the insurance table.  (There are multiple matches in the table.)
SELECT 
EpiscopalPatient.PatName, 
EpiscopalPatient.VisitNumber, EpiscopalPatient.MedRecordNumber,
EpiscopalInsurance.GuarName
 
FROM EpiscopalPatient 
LEFT JOIN EpiscopalInsurance 
ON EpiscopalPatient.MedRecordNumber = EpiscopalInsurance.MedicalRecordNumber

Open in new window

0
Comment
Question by:AmyFPA
4 Comments
 
LVL 4

Expert Comment

by:Tirocupidus
ID: 21832165
Does it matter which match it pulls from your insurance table?
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 21832202
<There are multiple matches in the table>
Are you saying that  there can be more than one row in EpiscopalInsurance for a single MedicalRecordNumber?
If not then the inclusion of Visit Number in the Select list will result in one row for every PatName/Visit combination in EpiscopalPatient
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 21832203
SELECT
EpiscopalPatient.PatName,
EpiscopalPatient.VisitNumber, EpiscopalPatient.MedRecordNumber,
Max(EpiscopalInsurance.GuarName) AS Guardian
 
FROM EpiscopalPatient
LEFT JOIN EpiscopalInsurance
ON EpiscopalPatient.MedRecordNumber = EpiscopalInsurance.MedicalRecordNumber
GROUP BY EpiscopalPatient.PatName,
EpiscopalPatient.VisitNumber, EpiscopalPatient.MedRecordNumber
0
 

Author Closing Comment

by:AmyFPA
ID: 31469196
You're wonderful!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

735 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