Saturday, April 24, 2010

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

Programmer Question

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?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails