Solved

Unwanted cartesian results (a chronic problem for me!)

Posted on 2008-06-20
4
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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