代码如下:–合并重复行 select * from A union select * from B –不合并重复行 select * from A union all select * from B 按某个字段排序 –合并重复行 select * from ( select * from A union select * from B) AS T order by 字段名 –不合并重复行 select * from ( select * from A union all select * fro
两个不同的表进行查询,需要把结果合并,
比如table1的列为 id, user_id, type_id,pro_id;
table2的列为 id,user_id,collect_id;分别如下图所示
table1:
table2:
将两个表的查询结果合并到一起的查询语句为
select *, null as collect_id from table1 where user_id = 527
union
select id,user_id,null as type_id,null as