以下查询返回0行,即使这两个表包含多个匹配值。
SELECT i.isrc, m.isrc FROM table1 i INNER JOIN table2 m ON i.isrc = m.isrc;
因为isrc列是varchar类型,所以我怀疑它可能是表排序规则的问题。但是,将两个排序规则更改为utf-8并没有解决问题。
这可能是什么问题?
答案 0 :(得分:2)
尝试下面的内容,
SELECT i.isrc, m.isrc
FROM table1 i
INNER JOIN table2 m
ON UPPER(TRIM(i.isrc)) = UPPER(TRIM(m.isrc))
注意:强>
答案 1 :(得分:0)
看一下你想法在每个表中匹配的值:
select src, sum(in1) as in1, sum(in2) as in2
from ((select distinct i.isrc as src, 1 as in1, 0 as in2 from table1 i) union all
(select distinct m.isrc as src, 0 as in1, 1 as in2 from table1 m)
) t
group by src;
在执行上述操作之前,您可能会发现有用的摘要:
select in1, in2, count(*), min(src), max(src)
from (select src, sum(in1) as in1, sum(in2) as in2
from ((select distinct i.isrc as src, 1 as in1, 0 as in2 from table1 i) union all
(select distinct m.isrc as src, 0 as in1, 1 as in2 from table1 m)
) t
group by src
) s
group by in1, in2;
对于group by
而言相同且对于比较来说相同的语义可能不一样(最后的空格会影响group by
的相似性但不应影响相似性的相等性, 例如)。但是,这将让您知道两个表中可以匹配的内容。