?
Solved

Cardinality  and outer join

Posted on 2012-03-21
7
Medium Priority
?
1,149 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 400 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 1200 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 400 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 1200 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 1200 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 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