Solved

Unwanted cartesian results (a chronic problem for me!)

Posted on 2008-06-20
4
296 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

746 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

9 Experts available now in Live!

Get 1:1 Help Now