Solved

Cardinality  and outer join

Posted on 2012-03-21
7
959 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
7 Comments
 
LVL 73

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

757 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

16 Experts available now in Live!

Get 1:1 Help Now