Solved

Natural Join in SQL

Posted on 2011-02-15
5
1,777 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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL Grouping 2 43
Determining creation & modification dates on MySQL tables 4 42
How to join on ID, with prefix? 15 60
when to use sequences in mysql 4 30
This article describes some very basic things about SQL Server filegroups.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

831 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