41 lines
947 B
Plaintext
41 lines
947 B
Plaintext
Omitting a join condition is a subtle, yet classic blunder. Do so, and you're guaranteed not to get the results you intended.
|
|
|
|
|
|
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.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
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
|
|
|
|
[source,text]
|
|
----
|
|
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 ...
|
|
----
|
|
|
|
|