Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Natural Join in SQL

Posted on 2011-02-15
5
Medium Priority
?
1,842 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

916 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