Connecting SQL Joins & Set Theory Concepts

Hi there. There is this interesting infographic I found which relates set theory to table joins in SQL.

Source: https://i.stack.imgur.com/UI25E.jpg

 

 

One can treat a database table as a set with elements being information within a table.

The set A refers to table A and the set B refers to table B.

Left Join

A left join selects everything from A including the intersection A \cap B. If the null part is TRUE then the intersection removed and the A only part would be selected which is like A - B = A \cap B^{c} .

Right Join

It would be similar with the right join with B where the intersection A \cap B is selected as well. If the null part is TRUE then the intersection removed and the A only part would be selected which is like B - A = B \cap A^{c}.

Inner Join

The SQL INNER JOIN portion of a query combined with select outputs the intersection A \cap B of tables A and B.

Full Outer Join

The FULL OUTER JOIN portion of the query take everything from table A, table B and the intersection A \cap B. If the key in table A and the key in table B IS NULL then the intersection A \cap B is removed.


References

The featured image/infographic is from http://i.stack.imgur.com/UI25E.jpg.

Leave a Reply