Solved

Cardinality  and outer join

Posted on 2012-03-21
7
1,111 Views
Last Modified: 2012-08-14
what is the best way to join the below.. FULL Outer or LEFT Outer?

Each TableB has Zero or more TableA (Outer Join) (Cardinality 0..n)
Each tableA has one more tableB (Cardinality 1..n)
0
Comment
Question by:25112
[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
7 Comments
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 100 total points
ID: 37747235
"best" is irrelevant when comparing those.

they are functionally different.  Use the one that returns the correct results.

If, because of particular data sets, the results are the same, then LEFT "should" be more efficient than "FULL"
0
 
LVL 6

Assisted Solution

by:SJCFL-Admin
SJCFL-Admin earned 300 total points
ID: 37747244
Create the query so that it makes sense from a business perspective FIRST.  If it then does not perform acceptibly under real life conditions, tune it.  Do not make every query a test in mathematics.

The main rule is to filter first and join second.  The optomizer handles most other considerations and should change what it needs to if the mathematics require it to....
0
 
LVL 12

Assisted Solution

by:sachitjain
sachitjain earned 100 total points
ID: 37747252
It totally depends on what do you want out of your query. I take one example.
Employee
EmpId      CityCode
1                 JAI
2                CHN
3                 null
4                 CHN

City
CityCode      CityName
JAI            Jaipur
CHN            Chennai
HYD            Hyderabad

This query
select EmpId, CityName from Employee left join City on Employee.CityCode = City.CityCode

would give you
EmpId        CityName
1                 Jaipur
2                Chennai
3                 null
4                 Chennai

and following query
select EmpId, CityName from Employee full outer join City on Employee.CityCode = City.CityCode

would give you
EmpId        CityName
1                 Jaipur
2                Chennai
3                 null
4                 Chennai
null             Hyderabad

So query with left join picks everything from entity set that is on left side of join and only selective records from entity set on the right based on join condition. On the other hand, full outer join considers all records from both the entity sets involved in join.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:25112
ID: 37747639
OK.. what is the significance of (Cardinality 0..n) vs (Cardinality 1..n)
0
 
LVL 6

Assisted Solution

by:SJCFL-Admin
SJCFL-Admin earned 300 total points
ID: 37747846
(Cardinality 1..n)
means that at least one or more row exists (thus you may get one match or one or multiples if it is on the relationship line that you are seeing this designation)

(Cardinality 0..n)
means that zero or more row exists (thus you may get no matches or one or multiples if it is on the relationship line that you are seeing this designation)

Different packages use different terminology. Cardinality generaly applies to uniqueness of keys.
0
 
LVL 6

Accepted Solution

by:
SJCFL-Admin earned 300 total points
ID: 37747877
LEFT OUTER JOIN means the table on your left can be considered your primary table of interest and you want all rows in that table to be included in your result set regardless of whether there is a match in the table on the right or not.  If there is no match in the table on the right, it will place nulls in the right tables field values...

Full Outer JOIN means join all permutation of keys on both sides.  If no match on the opposing side, nulls will be placed in the fields on the non-matching side.
 

Does this help clear up the confusion?
0
 
LVL 5

Author Comment

by:25112
ID: 37780094
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

728 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