• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1245
  • Last Modified:

Cardinality and outer join

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
25112
Asked:
25112
5 Solutions
 
sdstuberCommented:
"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
 
SJCFL-AdminCommented:
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
 
sachitjainCommented:
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
25112Author Commented:
OK.. what is the significance of (Cardinality 0..n) vs (Cardinality 1..n)
0
 
SJCFL-AdminCommented:
(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
 
SJCFL-AdminCommented:
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
 
25112Author Commented:
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now