Solved

Cardinality  and outer join

Posted on 2012-03-21
7
1,033 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delete the first occurence of a duplicate row in sql 5 38
Sum particular field in database 2 16
TSQL recursive CTE challenge... 8 29
Trouble with <> 2 21
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

837 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