[英]How to use inner join for 3 columns with condition MYSQL query
我在表 sample1 中有 2 個表有 key1 和 key2.... 在表 sample2 中有 tey1 和 tey2 和 tey3....
我想加入具有此條件的表 1_ if key1 = tey1 或 2_ if key2 = tey2 或 key2 = tey3
如果 key1 = tey1 不要檢查 key2 = tey2 或 key2 = tey3
我的查詢是:
Select *
from sample1 inner join sample2
on sample1.key1 = sample2.tey1 OR sample1.key2 = sample2.tey2 OR sample1.key2 = sample2.tey3
但它太慢了,我認為不是最佳的
select s1。 ,s2。 從 sample1 as s1, sample2 as s2 where s1.key1 = s2.tey1 OR s1.key2 = s2.tey2 OR s1.key2 = s2.tey3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.