Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Natural Join in SQL

Posted on 2011-02-15
5
1,783 Views
Last Modified: 2012-05-11
In SQL, how does natural join work?
0
Comment
Question by:JCW2
5 Comments
 
LVL 10

Accepted Solution

by:
himanshut earned 250 total points
ID: 34902803
0
 

Author Comment

by:JCW2
ID: 34909329
Can you explain natural join and inner join on this page?
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 34909636
copy from the wiki page:


Natural join
A natural join offers a further specialization of equi-joins. The join predicate arises implicitly by comparing all columns in both tables that have the same column-name in the joined tables. The resulting joined table contains only one column for each pair of equally-named columns.
Most experts agree that NATURAL JOINs are dangerous and should never be used.


when you look at the example(s) on that page, you can see it documented.
in short, compared to a normal join where you have to specify which columns have to be used to "join", the natural join will implicitly join on columns with the same name... which is very bad idea, as at some point, you might add another column (with the same name) to either table modifying the query's behavior dramatically.
0
 

Author Closing Comment

by:JCW2
ID: 34910530
Thank you for your help.
0
 
LVL 22

Expert Comment

by:dportas
ID: 35749999
Standard SQL does have a join operator called NATURAL JOIN. Eg: SELECT * FROM tbl1 NATURAL JOIN tbl2;
However:

- It is not really the same as the relational model operator called natural join and usually written as |X|
- The SQL version of natural join is not widely used and many people consider it poor practice to use it at all.
- Many SQL DBMSs don't even support the NATURAL JOIN operator (Oracle does. MS SQL Server doesn't).
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Creating and Managing Databases with phpMyAdmin in cPanel.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question