FROM
and JOIN
operators SQL-L031Avoid table aliases in FROM
clauses and JOIN
conditions,
as it’s harder to understand what the table called “c”
is compared to “customers”.
This rule is controversial and for many larger databases avoiding alias is neither realistic nor desirable. In this case this rule should be disabled.
SELECT
COUNT(o.customer_id) as order_amount,
c.name
FROM orders as o
JOIN customers as c on o.id = c.user_id
SELECT
COUNT(orders.customer_id) as order_amount,
customers.name
FROM orders
JOIN customers on orders.id = customers.user_id;
-- Self-join will not raise issue
SELECT
table1.a,
table_alias.b,
FROM
table1
LEFT JOIN table1 AS table_alias ON
table1.foreign_key = table_alias.foreign_key