0

有两张桌子

Table A
id column_a
01 abc
01 abc
02 abc
02 abc
02 abc
03 abc
03 abc
04 abc

表 B

id column_b
01 abc
02 abc
02 abc
03 abc
04 abc

我想比较上面的这两个表,并在表 a 中而不是在表 b 中得到结果,例如:

id column_a
01 abc
01 abc
02 abc
03 abc

我怎么能在 MySQL 中做到这一点?

非常感谢!

更新

4

3 回答 3

5
SELECT A.* FROM A
LEFT JOIN B ON A.column_a = B.column_b AND A.id = B.id
WHERE B.id IS NULL
于 2012-06-20T08:08:55.787 回答
2

尝试

SELECT A.* FROM A
LEFT JOIN B ON A.ID=B.ID AND A.column_a=B.column_b
WHERE B.ID IS NULL

问候

于 2012-06-20T08:21:40.740 回答
1

试试这个:

select a.id,a.column_a
from (select count(*) as a_num, id,column_a 
from table_a group by id having count(*) > 1) as a 
left join (select count(*) as b_num, id from table_b group by id having count(*) > 1) as b 
on a.a_num > b.b_num;
于 2012-06-21T06:25:04.273 回答