In SQL, a Join is actually an Intersection? And it is also a linkage or a "Sideway Union"?

Posted by Jian Lin on Stack Overflow See other posts from Stack Overflow or by Jian Lin
Published on 2010-04-24T20:43:19Z Indexed on 2010/04/24 20:53 UTC
Read the original article Hit count: 182

Filed under:
|
|
|
|

I always thought of a Join in SQL as some kind of linkage between two tables.

For example,

select e.name, d.name from employees e, departments d 
  where employees.deptID = departments.deptID

In this case, it is linking two tables, to show each employee with a department name instead of a department ID. And kind of like a "linkage" or "Union" sideway".

But, after learning about inner join vs outer join, it shows that a Join (Inner join) is actually an intersection.

For example, when one table has the ID 1, 2, 7, 8, while another table has the ID 7 and 8 only, the way we get the intersection is:

select * from t1, t2 where t1.ID = t2.ID

to get the two records of "7 and 8". So it is actually an intersection.

So we have the "Intersection" of 2 tables. Compare this with the "Union" operation on 2 tables. Can a Join be thought of as an "Intersection"? But what about the "linking" or "sideway union" aspect of it?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql