You’ve heard of inner, left, right, and outer joins, but do you know about NATURAL JOINS??
USING clause, which allows you to shortcut your writing of joins by only requiring the joining columns to be typed out once and returns those columns only once when you SELECT * from all your joined tables
Well, natural joins take that one step further, by eliminating the need to type out any join expression or join columns at all.
The only thing you need to ensure is that your joining columns are the same name and data type across your associated tables being joined
The result is like that of USING: only unique columns are kept in the output. But a difference is that you don’t specify aliases anywhere in your natural join query, whereas using USING, only the common joining columns don’t need aliasing
Also similar to USING, natural joins are supported by most major SQL dialects….again except SQL Server. Let’s just assume going forward none of my SQL tips are supported by SQL Server 😒
**WARNING** Because you don’t get to be explicit in your join criteria, you must do your due diligence beforehand to make sure you know of all the columns that will be used to naturally join your tables. Since data can always change, this shortcut should be used sparingly, especially in production code!
Important Notice for college students
If you’re a college student and have skills in programming languages, Want to earn through blogging? Mail us at firstname.lastname@example.org
Please subscribe to our Youtube Channel by clicking on the youtube icon given below