Conditional Inner Join

后端 未结 4 680
醉梦人生
醉梦人生 2021-02-05 05:12

I want to be able to inner join two tables based on the result of an expression.

What I\'ve been trying so far:

INNER JOIN CASE WHEN Reg         


        
4条回答
  •  感情败类
    2021-02-05 06:01

    SELECT
      R.foo, tr.bar
    FROM
      SomeTable AS R
      INNER JOIN RegistrationTypes AS RegT ON R.RegistrationTypeId = RegT.Id 
                                              AND RegT1.Type = 1
      INNER JOIN TimeRegistration AS tr    ON /* whatever */
    
    UNION 
    
    SELECT
      R.foo, dr.bar
    FROM
      SomeTable AS R
      INNER JOIN RegistrationTypes AS RegT ON R.RegistrationTypeId = RegT.Id 
                                              AND RegT1.Type = 2
      INNER JOIN DrivingRegistration AS dr ON /* whatever */
    

提交回复
热议问题