这个SQL要怎么写?

asp_net 2003-10-22 10:29:01
A表
s1 s2 s3 s4
张三 语文 80 期末考试
张三 数学 90 期末考试
李四 物理 78 期末考试
李四 语文 85 期末考试
王二 数学 80 期末考试
…… …… …… ……

B表
s1 s2 s3 s4
张三 语文 80 期末考试
波波 数学 90 期末考试
啊啊 物理 78 期末考试
李四 语文 85 期末考试
王二 数学 80 期末考试
…… …… …… ……

有2个同样的表A和B如上,要怎么选出2表中所有不重复的S1字段的记录.
如:张三\李四\王二\波波\啊啊
...全文
27 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzh1215 2003-10-22
  • 打赏
  • 举报
回复
select * from a where not exists( select * from b where a.s1=b.s1
and a.s2=b.s2 and a.s3=b.s3)
union
select * from b where not exists( select * from a where a.s1=b.s1
and a.s2=b.s2 and a.s3=b.s3)
goneaway 2003-10-22
  • 打赏
  • 举报
回复
select distinct * from
(
select s1 from a
union all
select s1 from b
) temp
kmbbo 2003-10-22
  • 打赏
  • 举报
回复

select distinct(s1) from A union select distinct(s1) from B
LoveSQL 2003-10-22
  • 打赏
  • 举报
回复
select distinct * from
(
select * from a
union
select * from b
) a
goneaway 2003-10-22
  • 打赏
  • 举报
回复
select distinct s1 from a
union
select distinct s1 from b
welyngj 2003-10-22
  • 打赏
  • 举报
回复

select * from a where not exists( select * from b where a.s1=b.s1
and a.s2=b.s2 and a.s3=b.s3 and a.s4=b.s4)
union
select * from b where not exists( select * from a where a.s1=b.s1
and a.s2=b.s2 and a.s3=b.s3 and a.s4=b.s4)
gmlxf 2003-10-22
  • 打赏
  • 举报
回复
select distinct s1 from
(
select s1 from a
union
select s1 from b
) a
Veeve 2003-10-22
  • 打赏
  • 举报
回复
select distinct s1 from a
union
select distinct s1 from b

34,591

社区成员

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

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