SQL 两次不同条件查询一张表的结果合并成一张表怎么做啊 比如结果1
结果2
怎么把'结果2'并在'结果1'的右边?大佬们帮帮我
union 是并在下面,我是想要并在右边
我不知道理解的意思对不对,你要把结果二拼接到结果一右边?
(select * from table1 where xx='xx') as table2 left join (select * from table3 where xx='xx' )as table4 on table2.id=table4.id
我觉得渊渟无迹静涛君的是对的,前面再加上select * from 就行了
用left join
https://blog.csdn.net/AinUser/article/details/77446901
合并结果两条sql语句的结果集可以使用union all操作,需要保证前后两条sql语句查询出来的字段是一样的
select * from .... where 条件1 union all select * from .... where 条件2 ,两条语句用 union all 链接起来就是一条语句,合并数据。
使用union all语句就可以。比如:
select '01' xx from dual union all select '02' xx from dual
只要保证select 和from 中间的字段名称都保持一致即可。两个查询间加什么条件都没关系