• xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    18
    ·
    edit-2
    1 year ago

    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.