1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
SELECT
(SELECT First(id_t1) FROM Table1 as t3
WHERE
(SELECT count(id_t1) FROM Table1 as t4 WHERE (t3.id_t1>=t4.id_t1) and (t3.ref=t4.ref) ORDER BY count(id_t1))
>=
(SELECT count(id_t2) FROM Table2 as t1 WHERE (t2.id_t2>=t1.id_t2) and (t2.ref=t1.ref) ORDER BY count(id_t2))
AND (t3.ref=t2.ref)
) as id1,
id_t2 as id2,
ref
FROM Table2 as t2
UNION
SELECT
id_t1 as id1,
(SELECT First(id_t2) FROM Table2 as t3
WHERE
(SELECT count(id_t2) FROM Table2 as t4 WHERE (t3.id_t2>=t4.id_t2) and (t3.ref=t4.ref) ORDER BY count(id_t2))
>=
(SELECT count(id_t1) FROM Table1 as t1 WHERE (t2.id_t1>=t1.id_t1) and (t2.ref=t1.ref) ORDER BY count(id_t1))
AND (t3.ref=t2.ref)
) as id2,
ref
FROM Table1 as t2 |
Partager