SQL查询结果的纵向连接

 
 
 
复制代码
  1. select xmmc from sbs where xh = ‘123456’
  查询结果为: 

项目A

 
复制代码
  1. select xmmc from sbs where xh = ‘7890’
  查询结果为: 

项目B

欲把两个查询结果纵向连接起来,只需要执行以下SQL:
 
复制代码
  1. (select xmmc from sbs where xh = ‘123456’)   union   (select xmmc from sbs where xh = ‘7890’  )
查询结果为:

项目A
项目B


用法约束:
1.  前后select 的字段数必须一样。但select的字段名不一定要一致
2.  后可加order by 但必须是select 中出现的字段名
3. 以上使用于sql server ,其它数据库下尚未测试
原文地址:https://www.cnblogs.com/htys/p/3192790.html