2020-06-30 16:59:06 +02:00
Omitting a join condition is a subtle, yet classic blunder. Do so, and you're guaranteed not to get the results you intended.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when a table is included in the ``++FROM++`` list but not in the ``++WHERE++`` list in relation to other tables, and when only part of a compound key is used in the conditions.
2020-06-30 16:59:06 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 16:59:06 +02:00
----
SELECT p.name, f.name
FROM product p,
product_feature f -- Noncompliant
WHERE p.id=?
SELECT p.name, ck.date
FROM product p
JOIN compound_key_table ck
ON p.manufacturer_product_id=ck.manufacturer_product_id -- Noncompliant
WHERE ...
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 16:59:06 +02:00
----
SELECT p.name, f.name
FROM product p,
product_feature f
WHERE p.id=f.product_id AND p.id=?
SELECT p.name, ck.date
FROM product p
JOIN compound_key_table ck
ON p.manufacturer_product_id=ck.manufacturer_product_id AND p.manufacturer_id=ck.manufacturer_id
WHERE ...
----