Hello my dear friends. Today we will learn about SQL Joins and my new little app that helps to build and understand them.
A SQL join clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as is. A JOIN is a means for combining fields from two tables by using common values. ANSI-standard SQL specifies five types of a JOIN: INNER, LEFT OUTER, RIGHT OUTER, FULL OUTER and CROSS. As a special case, a table (base table, view, or joined table) can JOIN to itself in a self-join.
SQL Joins Visualizer
If you have tried to understand how joins work and constantly get confused which join to use, you just need to use a new simple app – SQL Joins Visualizer. It’s using Venn diagram to build a valid SQL join with an explanation. Application can work offline.
To select an appropriate type of join between two tables you need to click at the sectors on Venn diagram. For example, if you want to get the results that contain the whole table A, you will see that it is enough to use the “LEFT JOIN”. You will get “INNER JOIN”, if your JOIN results need to include both A and B results.
Of course, this application is open source.
There’s also a cartesian product or cross join, which as far as I know, can’t be expressed as a Venn diagram:
SELECT * FROM TableA CROSS JOIN TableB
It joins “everything to everything”, resulting in 4 x 4 = 16 rows, far more than we had in the original sets. If you do the math, you can see why this is a very dangerous join to run against large tables.
SQL Joins Visualizer helps you build SQL JOIN between two tables by using of Venn diagrams. I hope it will help to understand how SQL joins are working.
That’s all folks! Thank you for reading till the end.