1. 程式人生 > >SQL用and和or多表查詢笛卡爾積

SQL用and和or多表查詢笛卡爾積

原因:and或or都要有過濾條件才行,比如

SELECT T1.*
  from T_DC_ORDER_CENTER_DETAIL T1, TD_S_COMMPARA T2
 WHERE T1.CHANNEL_CODE = T2.VALUEC1
   AND T1.AUDIT_FLAG is null
    or (T1.AUDIT_FLAG = 2 and T1.CHANNEL_CODE = T2.VALUEC1)

或者用union all將and和or條件分開