AP 11 - Avoid implicit column references

Severity

Warning Warning

Type

Readability

Correctness

Problem

Don’t use implicit columns references in queries with multiple table joins.

SELECT col3
      ,col4
  FROM tableA a
  JOIN tableB b
    ON col1=col2

In the example above it is not clear if the columns col1, col2, col3, col4 belong to tableA or tableB. Readability suffers and you increase the risk of introducing bugs in the code.

Solution

Explicitly reference each column

SELECT a.col3
      ,b.col4
  FROM tableA a
  JOIN tableB b
    ON a.col1=b.col2

In this example each column is referenced by its table alias.

Legitimate use of the anti pattern

If you only have one table in your query you can use implicit column references.