2017-02-13 53 views
0

我有這個疑問不是從左邊的所有字符串加入

select delivery_first_week_repo.type, delivery_first_week_repo.from_sale, delivery_week_repo.from_sale 
from delivery_first_week_repo 
LEFT JOIN delivery_week_repo on delivery_first_week_repo.type = delivery_week_repo.type 
where delivery_first_week_repo.week_day = 'Tuesday' 
and delivery_week_repo.week_day = 'Tuesday' 

delivery_first_week_repo有一些字符串類型至極不是第二個表。但它們不會根據要求顯示。

+0

顯示所需結果集的表格數據 –

回答

1

當有在第二個表中沒有匹配行,從第二個表中的列將是無效的加入。所以delivery_week_repo.week_day = 'Tuesday'永遠不會是真的那些行。

第二張桌子上的條件應該放在ON條款中,而不是WHERE條款。

select delivery_first_week_repo.type, delivery_first_week_repo.from_sale, delivery_week_repo.from_sale 
from delivery_first_week_repo 
LEFT JOIN delivery_week_repo on delivery_first_week_repo.type = delivery_week_repo.type 
    and delivery_week_repo.week_day = 'Tuesday' 
where delivery_first_week_repo.week_day = 'Tuesday' 
0

這是因爲LEFT JOIN類型。

使用內加入將goive你匹配結果

select delivery_first_week_repo.type, 
delivery_first_week_repo.from_sale, delivery_week_repo.from_sale 
from delivery_first_week_repo 
INNER JOIN delivery_week_repo on delivery_first_week_repo.type = 
delivery_week_repo.type 
where delivery_first_week_repo.week_day = 'Tuesday' 
and delivery_week_repo.week_day = 'Tuesday' 
+0

'INNER JOIN'不會顯示沒有匹配的行。他想看到他們。 – Barmar

+0

他在查詢中使用'and delivery_week_repo.week_day ='Tuesday',使得他的'LEFT JOIN'像'INNER JOIN'一樣行事,因爲它過濾掉了所有不匹配的行。 – Barmar

相關問題