Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Natural Join in SQL

Posted on 2011-02-15
5
Medium Priority
?
1,829 Views
Last Modified: 2012-05-11
In SQL, how does natural join work?
0
Comment
Question by:JCW2
[X]
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
5 Comments
 
LVL 10

Accepted Solution

by:
himanshut earned 1000 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 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