我有2個表,顯示如下簡化:左加入與OR子句
Table 1: | id | somedata | checkcode
Table 2: | id | somedata | checkcode1 | checkcode2
我需要左加入第二個,其中checkcode1 OR checkcode2就像註冊碼。我試圖做出兩個不同的左連接,但這不起作用,因爲它包含了兩倍的數據。
我需要的是這樣的:
Select * from Table1 as t1
LEFT JOIN Table2 as t2
on t1.checkcode = (t2.checkcode1 OR t2.checkcode2)
這可能嗎?
你嘗試簡單明確寫入的條件? 'Select * from Table1 as t1 LEFT JOIN Table2 as t2 on(t1.checkcode = t2.checkcode1 OR t1.checkcode = t2.checkcode2)' –
yay this worked!如果你把它作爲回答,我接受你,因爲你是第一個。謝謝! – sharkyenergy
這裏有一條線索:IN() – Strawberry