27 lines
593 B
Plaintext
27 lines
593 B
Plaintext
Sometimes a join through table B is required to get from table A to table C. But when the table B join values are present in A and C, and nothing else from B is used in the query, the join to B can be eliminated, thereby improving performance and enhancing code clarity.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
SELECT A.name, C.department
|
|
FROM A
|
|
JOIN B ON A.c_id=B.c_id -- Noncompliant; redundant
|
|
JOIN C on B.c_id = C.c_id
|
|
WHERE A.id = 12
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,text]
|
|
----
|
|
SELECT A.name, C.department
|
|
FROM A
|
|
JOIN C on A.c_id = C.c_id
|
|
WHERE A.id = 12
|
|
----
|
|
|
|
|