4 ms·
I prefer any formatting over no formatting. If had to choose then I would do this: * Lowercase for tables & columns and upper case for syntax. * Having comma
by iblaine 10y ago
I prefer any formatting over no formatting. If had to choose then I would do this:
* Lowercase for tables & columns and upper case for syntax.
* Having commas first makes it easier to move lines around.
* I avoid small aliases to minimize conflicts when code is resused.
* Every column needs a table reference. Do not make me guess.
* Alias every column in the SELECT clause.
SELECT
table1.col1 AS table_col1
, table2.col2 AS table_col2
, table3.col3 AS table_col3
FROM
table1 table1
INNER JOIN
table2 table2
ON
table1.col2 = table2.col1
INNER JOIN
table3 table3
ON
table1.col3 = table3.col1
AND table3.col2 = something_else
WHERE
table1.col1 > 0
AND table2.col2 <> table1.col4
ORDER BY
table2.col2
LIMIT 100;