I've been trying to understand the concept of sql joins fully, venn diagrams have helped me a lot to do that. I've found them for all kind of joins but not for natural joins.
How would a venn diagram for a natural join look like?
I've been trying to understand the concept of sql joins fully, venn diagrams have helped me a lot to do that. I've found them for all kind of joins but not for natural joins.
How would a venn diagram for a natural join look like?
Copyright © 2021 Jogjafile Inc.
Venn diagrams are not very helpful for understanding natural (inner) join--or any join, natural or not. Most Venn diagrams associated with joins on Stack Overflow and the web are parroted worthless misrepresentations--even in cases where a Venn diagram could be useful.
Here are some valid uses of Venn diagrams for SQL natural join:
We can have an area be a set whose elements are an associated table's column names. Then the left and right circle elements are the left and right table column names, the overlap elements are the common column names (which must appear once in each input table), and the combined elements are the result's column names. But a SQL table can have duplicate column names, and columns are ordered; so this doesn't give the result column list.
We can have an area be a set whose elements are the distinct subrow values under the common columns. Then the left and right circle elements are the left and right table subrow values, and the overlap elements are the result subrow values. But this doesn't give how many times a subrow value appears in a table. In particular, when all columns are common, so the subrow values are the row values, this doesn't give how many times a row value appears in the result.
Neither diagram nor the pair gives what the output rows are in general.
From my answer at CROSS JOIN vs INNER JOIN in SQL :
I repeat with emphasis:
From one of my comments on an answer there re its Venn diagram for inner join:
From one of my comments on What is the difference between "INNER JOIN" and "OUTER JOIN"? :
And another:
So Venn diagrams are relevant for certain cases where tables can reasonably be considered to hold sets of row-valued elements. But in general SQL tables do not hold sets of row-valued elements, while Venn diagrams denote sets.
Re illustrating inner vs outer joins via Venn diagrams:
From my comment on LEFT JOIN vs. LEFT OUTER JOIN in SQL Server :
From my comment on my answer to What is the difference between "INNER JOIN" and "OUTER JOIN"? :
See also my answer at Inner Join vs Natural Join vs USING clause: are there any advantages? .
PS Often diagrams are called Venn diagrams when they are really Euler diagrams.