mysql查询两张表中 两个字段的值不重复的数据

南明北月 2016-06-23 05:38:17





mysql查询两张表中 两个字段的值不重复的数据。A表中的oid和B表中的useoid中的数据有些事相同的。但是当查询A表的时候,oid如果和B表中useoid字段中的数据有重复,就不用查出来。
在查询A表的时候,B表中的useroid如果有和A表中的oid有重复的话就不用显示
...全文
1973 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
卖水果的net 版主 2016-06-24
  • 打赏
  • 举报
回复
引用 4 楼 qq_27246087 的回复:
[quote=引用 1 楼 wmxcn2000 的回复:]
-- 大概这个样子
select * from a 
union all
select from b where not exists(select * from a where a.id = b.id and a.no= b.no)
上面那个写错了 [SQL]select * from tb_order a union all select * from tb_usermagic b where not exists(select * from tb_order a where a.oid = b.useOid and a.no= b.no) [Err] 1054 - Unknown column 'a.no' in 'where clause'[/quote] 你把列名,要换成你的自己的,我只是写个例子; PS: 楼主有点懒啊。
中国风 2016-06-24
  • 打赏
  • 举报
回复
SELECT * FROM A AS T WHERE OID IN (
SELECT Oid FROM A WHERE NOT EXISTS(SELECT 1 FROM B WHERE UseOid=A.Oid) GROUP BY Oid HAVING COUNT(*)=1)
南明北月 2016-06-24
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
-- 大概这个样子
select * from a 
union all
select from b where not exists(select * from a where a.id = b.id and a.no= b.no)
上面那个写错了 [SQL]select * from tb_order a union all select * from tb_usermagic b where not exists(select * from tb_order a where a.oid = b.useOid and a.no= b.no) [Err] 1054 - Unknown column 'a.no' in 'where clause'
南明北月 2016-06-24
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
-- 大概这个样子
select * from a 
union all
select from b where not exists(select * from a where a.id = b.id and a.no= b.no)
[SQL]select * from tb_order a union all select * from tb_usermagic b where not exists(select * from tb_order a where a.oid = b.useOid and a.oid.no= b.useOid.no) [Err] 1054 - Unknown column 'a.oid.no' in 'where clause'
依然不逆 2016-06-23
  • 打赏
  • 举报
回复
select * from A where not exists(select 1 from B where A.od=B.useroid)
卖水果的net 版主 2016-06-23
  • 打赏
  • 举报
回复
-- 大概这个样子
select * from a 
union all
select from b where not exists(select * from a where a.id = b.id and a.no= b.no)

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧