select distinct c.* from (select a.* from a union select b.* from b) c
select a.* from a union select b.* from b where b.id not in(select a.id from a)试试这个呢
要提高效率的话,改数据库结构、加索引 目前1 aaa 这样的数据在两个表里面都有,应该合并
如果单纯的记录重复使用union即可去掉重复记录 select a.* from a union select b.* from b
同意楼上的,用Union,可以自动过滤掉重复记录,如果不要自动过滤的话,就用Union All
还不如直接用 cross join-_-
使用 select a.* from a union select b.* from b where b.id not in(select a.id from a) 需要过滤重复的数据 select a.* from a union all select b.* from b where b.id not in(select a.id from a) 如果用union all 则SQL运行是单个运行然后把结果合并处理.这样不需要排序.
目前1 aaa 这样的数据在两个表里面都有,应该合并
select a.* from a
union
select b.* from b
select a.* from a union select b.* from b where b.id not in(select a.id from a)
需要过滤重复的数据
select a.* from a union all select b.* from b where b.id not in(select a.id from a)
如果用union all 则SQL运行是单个运行然后把结果合并处理.这样不需要排序.