What is the accepted practice for indenting SQL statements? For example, consider the following SQL statement:
SELECT column1, column2
FROM table1
WHERE column3 IN
(
SELECT TOP(1) column4
FROM table2
INNER JOIN table3
ON table2.column1 = table3.column1
)
How should this be indented? Many thanks.
This is my personal method. Depending on the length of the join condition I sometimes indent it on the line below.
What I usually do is,
I don't know if there's a standard but I like to do it this way;
because I can read and analyze the SQL better.
This is pretty short and easy to read. I'd make adjustments if there were more columns selected or more join conditions.
Yeah, this is pretty subjective...But here's my 2 cents:
But, really, I'd probably rewrite it without the IN:
Basically, my rules are: