1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LEFT JOINの最深部でWhereを追加する方法

Last updated at Posted at 2022-03-14

(
    D_ACCEPTHEAD
    LEFT JOIN
        D_9145_GENKA_SEISAN ON
        D_ACCEPTHEAD.ACEH_ACCEPTNO = DGS145_JYU_DEN_NO
)
LEFT JOIN

where句で絞り込みたい対象テーブルを字下げする

(
        D_ACCEPTHEAD
        LEFT JOIN
            D_9145_GENKA_SEISAN ON
            D_ACCEPTHEAD.ACEH_ACCEPTNO = DGS145_JYU_DEN_NO
)
LEFT JOIN

かっこを追加してくくる

(
    (
        D_ACCEPTHEAD
        LEFT JOIN
            D_9145_GENKA_SEISAN ON
            D_ACCEPTHEAD.ACEH_ACCEPTNO = DGS145_JYU_DEN_NO
    )
)
LEFT JOIN

くくったエリアを from 句として、select * Where句を追加する

(
    SELECT *
    FROM 
    (
        D_ACCEPTHEAD
        LEFT JOIN
            D_9145_GENKA_SEISAN ON
            D_ACCEPTHEAD.ACEH_ACCEPTNO = DGS145_JYU_DEN_NO
    )
    WHERE
        D_ACCEPTHEAD.ACEH_ACCEPTNO = '1'
)
LEFT JOIN

追加した select * を内包するカッコの最後に、別名をつける

(
    SELECT *
    FROM 
    (
        D_ACCEPTHEAD
        LEFT JOIN
            D_9145_GENKA_SEISAN ON
            D_ACCEPTHEAD.ACEH_ACCEPTNO = DGS145_JYU_DEN_NO
    )
    WHERE
        D_ACCEPTHEAD.ACEH_ACCEPTNO = '1'
) AS ACH_NOU
LEFT JOIN

別名(AS ACH_NOU)を付ける位置を間違えやすいので、注意!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?