SELECT COUNT(id1) FROM table1 INNER JOIN table2 ON table1.id1 = table2.id OR table1.id2 = table2.id HAVING COUNT(id1) > 1
to lengyuehui: 这个方法不行,比如tabel2中只有01,也会被提示。正常情况下是在表2中同时出现01、02或者01、03才会提示的。
可以用in或者existsselect * from table1 where id1 in (select id from table2) and id2 in (select id from table2)select * from table1 a where exists (select id from table2 where id = a.id1) and exists (select id from table2 where id = a.id2)
SELECT COUNT(id1) FROM table1 INNER JOIN table2 ON table1.id1 = table2.id OR table1.id2 = table2.id
HAVING COUNT(id1) > 1
这个方法不行,比如tabel2中只有01,也会被提示。正常情况下是在表2中同时出现01、02或者01、03才会提示的。