you are viewing a single comment's thread
view the rest of the comments
[–] 18 points 2 years ago* (last edited 2 years ago) (3 children)

Sorry, to clarify, not everything is in all caps. I'll append my prefered syntax below

WITH foo AS (
    SELECT id, baz.binid
    FROM
            bar
        JOIN baz
            ON bar.id = baz.barid
)
SELECT bin.name, bin.id AS binid
FROM
        foo
    JOIN bin
        foo.binid = bin.id

The above is some dirt simple SQL, when you get into report construction things get very complicated and it pays off to make sure the simple stuff is expressive.

  • source
  • parent
  • hideshow 6 child comments
  • [–] 12 points 2 years ago (2 children)

    You indent your JOIN? Why on earth? It lives in the same context as the SELECT.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 9 points 2 years ago

    I've seen both approaches and I think they're both quite reasonable. An indented join is my preference since it makes sub queries more logically indented... but our coding standards allow either approach. We've even got a few people that like

    FROM foo
    JOIN bar ON foo.id = bar.fooid
    JOIN baz ON bar.id = baz.barid
    
  • source
  • parent