两个表用union怎么写sql语句

gigilee 2005-02-18 11:46:37
表A
f1 f2 f3
a1 b1 c1
a2 b2 c2


表B
f1 f2 f3 f4
a1 b1 c3 d1
a2 b1 c3 d1

想取出一个记录集合并2个表的数据
以表A为基准,key 为 f1, f2

结果为
f1 f2 f3
a1 b1 c1
a2 b2 c2
a2 b1 c3

用union 是否可以实现
...全文
157 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gigilee 2005-02-18
  • 打赏
  • 举报
回复
where (f1+f2) not in(select f1+f2 from 表A)
是什么
gigilee 2005-02-18
  • 打赏
  • 举报
回复
楼上的是什么数据库阿
gigilee 2005-02-18
  • 打赏
  • 举报
回复
楼上的是什么数据库阿
zyg0 2005-02-18
  • 打赏
  • 举报
回复
select f1,f2,f3 from 表A
union all
select f1,f2,f3 from 表B where (f1+f2) not in(select f1+f2 from 表A)
避免重复记录
select f1,f2,f3 from 表A
union all
select f1,f2,f3 from 表B
完全合彬

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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