When you need access to data from multiple tables, it is more efficient, effective, and understandable to use pre-built views than to select the data from a large number of tables - effectively creating in-memory views - at runtime.


== Noncompliant Code Example

With a maximum number of 3 joined tables:

----
SELECT PERSONS.NAME, COUNTRIES.NAME, GENRES.NAME, PROFESSIONS.NAME
FROM PERSONS 
  INNER JOIN COUNTRIES ON COUNTRIES.ID = PERSON.COUNTRY_ID
  INNER JOIN GENRES ON GENRES.ID = PERSONS.GENRE_ID
  INNER JOIN PROFESSIONS ON PROFESSIONS.ID = PERSONS.PROFESSIONS_ID  -- Noncompliant; this is table #4
WHERE COUNTRIES.CODE = 'US'

SELECT PERSONS.NAME, COUNTRIES.NAME, GENRES.NAME, PROFESSIONS.NAME
FROM PERSONS, COUNTRIES, GENRES, PROFESSIONS -- Noncompliant
WHERE COUNTRIES.CODE = 'US' AND COUNTRIES.ID = PERSON.COUNTRY_ID AND GENRES.ID = PERSONS.GENRE_ID AND PROFESSIONS.ID = PERSONS.PROFESSIONS_ID
----


