I've two table (t1
and t2
) with 3 identical integer columns: c1
, c2
and c3
. I want to count how many value in t1
are in t2
.
SELECT count(t1.value) FROM t1 INNER JOIN t2 ON (
t1.c1 = t2.c1 OR t1.c1 = t2.c2 OR t1.c1 = t2.c3 OR
t1.c2 = t2.c1 OR t1.c2 = t2.c2 OR t1.c2 = t2.c3 OR
t1.c3 = t2.c1 OR t1.c3 = t2.c2 OR t1.c3 = t2.c3
)
It doesn't seems a good way to write it (I'll have to add some columns). Is there a better solution to write it without enumerated any possibilities?
I'm using MySQL version 5.6.
c1 = 1, c2 = 1, and c3 = 2
and the t2 has the values1
and2
somewhere, should that count as 1, 2, or 3 in the final total? \$\endgroup\$t1.c1
,t1.c2
andt1.c3
are all different. Idem for t2. So your example @rolfl should count 2. \$\endgroup\$