I have Two tables :
T1
"IdT1;i1T1,n2T1 1;123;n2T1 2;234;n3T1 3;345;n4T1 4;678;n1T1 5;123;n2T1 6;234;n3T1
T2
"idT2;n1T2;n2T2;i1T2 1;1n1T2;2n1T2;123 2;1n2T2;2n1T2;234 3;1n3T2;2n1T2;345 4;1n4T2;2n1T2;456 5;1n5T2;2n1T2;567 6;1n6T2;2n1T2;678
In SQLITE3
$req = $db -> prepare("SELECT T2.n1T2, T2.n2T2, //COUNT(*) FROM T1 INNER JOIN T2 ON T1.idT2 = T2.idT2 "); if ($res = $req->execute()) { $arr = $res->fetchArray(); var_dump($arr); }
I search for n1T2 and n2T2 names, the count of same values between i1T1 and i1T2
example: 1n1T2;2n1T2;2 1n2T2;2n2T2;2 1n3T2;2n1T2;1 ...
I var_dump for display, in wait best method
Advertisement
Answer
It looks like you want a join and aggregation:
select t2.n1t2, t2.n2t2, count(*) cnt from t1 inner join t2 on t2.i1t2 = t1.i1t1 group by t2.n1t2, t2.n2t2