mysql筛选两个不同表的数据 | 您所在的位置:网站首页 › 两个表重复值怎么筛选 › mysql筛选两个不同表的数据 |
用法1:
筛选a表与在b表中不相同的数据(但不筛选出b表与在a表中不相同的数据) ----例如a表中有 - 【张三,李四,王五】 b表中有【张三,李四,赵六】 ----用公式 select * from a where (select count(1) from b where a.name = b.name)= 0 ---------筛选出结果 -【王五】 ----用公式 select * from b where (select count(1) from a where a.name = b.name)= 0 ---------筛选出结果 -【赵六】 总结:如果是a表在语句前,无论b表中有多少不相同的数据,只筛选出a表不相同的数据,相反如果b表在前,只筛选出b表里的数据 用法2:筛选a表与在b表中相同的数据 ----例如a表中有 - 【张三,李四,王五】 b表中有【张三,李四,赵六】 ----用公式 select * from a where (select count(1) from b where a.name = b.name)= 1 ---------则筛选出结果为 - 【张三,李四】 ----用公式 select * from b where (select count(1) from a where a.name = b.name)= 1 ---------同样筛选出结果为 -【张三,李四】 总结:无论两张表的数据如何不同,只筛选2张表相同的数据 |
CopyRight 2018-2019 实验室设备网 版权所有 |