Strange / esoteric join syntax

前端 未结 2 1632
灰色年华
灰色年华 2021-01-29 05:01

I\'ve been provided this old SQL code (table names changed) to replicate, and the JOIN syntax isn\'t something I\'ve seen before, and is proving hard to google:

         


        
2条回答
  •  遥遥无期
    2021-01-29 05:32

    I ran it by a colleague who figured it out:

    select 
    
    from A
    
    inner join B
    on A.ID = B.A_ID
    
    inner join ( C  -- put a bracket here...
    
    inner join D
    ON C.C_ID = D.C_ID
    
    ) -- and one here
    
    ON B.C_ID = D.C_ID
    

    or to format it a little nicer:

    select 
    
    from A
    
    inner join B
    on A.ID = B.A_ID
    
    inner join ( 
        C
        inner join D
        ON C.C_ID = D.C_ID
    )
    ON B.C_ID = D.C_ID
    

    I wasn't familiar with this kind of "sub-join" (I don't know what it's called), but this is much more readable and clear

提交回复
热议问题