[英]How to use inner join for 3 columns with condition MYSQL query
I have 2 tables in table sample1 have key1 and key2.... in table sample2 have tey1 and tey2 and tey3....我在表 sample1 中有 2 个表有 key1 和 key2.... 在表 sample2 中有 tey1 和 tey2 和 tey3....
i want join tables with this condition 1_ if key1 = tey1 Or 2_ if key2 = tey2 or key2 = tey3我想加入具有此条件的表 1_ if key1 = tey1 或 2_ if key2 = tey2 或 key2 = tey3
and if key1 = tey1 dontcheck key2 = tey2 or key2 = tey3如果 key1 = tey1 不要检查 key2 = tey2 或 key2 = tey3
my querie is:我的查询是:
Select *
from sample1 inner join sample2
on sample1.key1 = sample2.tey1 OR sample1.key2 = sample2.tey2 OR sample1.key2 = sample2.tey3
but it's too slow and i think not optimal但它太慢了,我认为不是最佳的
select s1. select s1。 ,s2. ,s2。 from sample1 as s1, sample2 as s2 where s1.key1 = s2.tey1 OR s1.key2 = s2.tey2 OR s1.key2 = s2.tey3从 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.