SQL 列不同的表查询结果合并 |
您所在的位置:网站首页 › 两张表组合查询 › SQL 列不同的表查询结果合并 |
两个不同的表进行查询,需要把结果合并, 比如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 pro_id, collect_id from table2 where user_id = 527; 结果为:
其实就是把对应的列补充到没有该列的表中,在例子中就是把collect_id补充到table1中, 把type_id,pro_id补充到table2中。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |