两个sql语句一样只有条件不一样,如何取并集?

cxy_ll 2003-01-14 10:37:28
select a,b,c... from t_x
where date>2000

select a,b,c... from t_x
where date>2002

这两个sql本来是一个sql只是条件不一样了,但现在要用一个sql写出来,取结果的并集,该怎么写?
...全文
517 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhambobo 2003-01-14
  • 打赏
  • 举报
回复
select a.*,b,* from (select a,b,c... from t_x where date>2000) a,(select a,b,c... from t_x where date>2002) b where a.id=b.id;
dyw 2003-01-14
  • 打赏
  • 举报
回复
只用where date>2000就行了



cxy_ll 2003-01-14
  • 打赏
  • 举报
回复
需要a,b,c,a,b,c
ohwww 2003-01-14
  • 打赏
  • 举报
回复
我觉得也是,只要date>2000这个条件不就可以了吗???
Robertlee3511 2003-01-14
  • 打赏
  • 举报
回复
各位楼上的,
你们只需要运行第一条语句就好了,第二条语句多余,你们仔细想想看。
beckhambobo 2003-01-14
  • 打赏
  • 举报
回复
也可这样:

select a,b,c,... from t_x where date between n and m;
  • 打赏
  • 举报
回复
select a,b,c,... from t_x where date>2000 or date>2000

select a,b,c... from t_x
where date>2000
union
select a,b,c... from t_x
where date>2002
tchatcha 2003-01-14
  • 打赏
  • 举报
回复
select a,b,c,... from t_x where date>2000 or date>2000;
用or连接两个条件
Robertlee3511 2003-01-14
  • 打赏
  • 举报
回复
那也好说,就用第二个吧!
那就是交集。
cxy_ll 2003-01-14
  • 打赏
  • 举报
回复
这是交集不是并集

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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