Avoid NATURAL JOIN queries | CAST Appmarq

Avoid NATURAL JOIN queries


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

Health Factor

  Efficiency


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.

Benchmark Statistics

Global Compliance

100.00%

Total Violations
0
Total Opportunities
351,089
Average Violations / App.
0.00
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Telecommunications

99.99%

Don't Know

100.00%

Energy

100.00%