Rule Definition
NATURAL JOIN is a type of equi-join which implicitly compares all identically-named columns of the two tables. While this a feature which may seem convenient at first, it becomes hard to maintain over time.
Remediation
Check the statement and if so, replace NATURAL JOINs with INNER JOINs.
Violation Code Sample
SELECT first_name, department_name
FROM employees
NATURAL JOIN departments;
Fixed Code Sample
The following example:
SELECT first_name, department_name
FROM employees
NATURAL JOIN departments;
should be rewritten as:
SELECT first_name,department_name
FROM employees
JOIN departments
ON (employees.manager_id = departments.manager_id
AND employees.department_id = departments.department_id);
or as:
SELECT first_name, department_name
FROM employees
JOIN departments
USING(manager_id, department_id);
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.