2018年3月13日火曜日

近年まれに見るどうでもよさ

みんなラブワイフ弁当かよ!<何が ごきげんよう。

SQL書くときのJOINとかONのインデントの自分ルールがなかなか
定まらなくてですね。(どうでもいいよ)
最近の書き方だけでも3通りもあります。

FROM
    entries
    LEFT OUTER JOIN comments ON
        entries.blog_id = comments.blog_id
        AND entries.entry_id = comments.entry_id

FROM
    entries
    LEFT OUTER JOIN comments
        ON entries.blog_id = comments.blog_id
        AND entries.entry_id = comments.entry_id

FROM
    entries
    LEFT OUTER JOIN comments
        ON
            entries.blog_id = comments.blog_id
            AND entries.entry_id = comments.entry_id

さらにJOIN句がサブクエリだったりするともう収拾つきません…。



FROM
    entries
    LEFT OUTER JOIN (
        SELECT
            ...
        FROM
            comments
        WHERE
            ...
    ) AS c ON
        entries.blog_id = c.blog_id
        AND entries.entry_id = c.entry_id

FROM
    entries
    LEFT OUTER JOIN (
        SELECT
            ...
        FROM
            comments
        WHERE
            ...
    ) AS c
        ON
            entries.blog_id = c.blog_id
            AND entries.entry_id = c.entry_id

FROM
    entries
    LEFT OUTER JOIN
        (
            SELECT
                ...
            FROM
                comments
            WHERE
                ...
        ) AS c ON
            entries.blog_id = c.blog_id
            AND entries.entry_id = c.entry_id

FROM
    entries
    LEFT OUTER JOIN
        (
            SELECT
                ...
            FROM
                comments
            WHERE
                ...
        ) AS c
        ON
            entries.blog_id = c.blog_id
            AND entries.entry_id = c.entry_id

0 件のコメント :

コメントを投稿