首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

三张表的格式都一模一样 如何合并成一张表?

2012-02-08 
三张表的格式都一模一样 怎么合并成一张表??三张表的字段格式都一模一样 怎么合并成一张表如a表b表c表d表i

三张表的格式都一模一样 怎么合并成一张表??
三张表的字段格式都一模一样 怎么合并成一张表



a表               b表             c表                                   d表
id   name       id   name     id   name             ?=         id,name




[解决办法]
select * from (
select id,name from a表
union all
select id,name from b表
union all
select id,name from c表)d

[解决办法]

select id,name into D from a表
union
select id,name from b表
union
select id,name from c表

union和union all的区别是一个过滤重复记录一个不过滤重复记录
[解决办法]
--查詢3張表的所有記錄,則用
select * from (
select id,name from a表
union all
select id,name from b表
union all
select id,name from c表)d

--查詢3張表中沒有重復的記錄,則用
select * from (
select id,name from a表
union
select id,name from b表
union
select id,name from c表)d

--union all 比 union 的效率高

[解决办法]
三张表的字段格式都一模一样 怎么合并成一张表



a表 b表 c表 d表
id name id name id name ?= id,name

select * into d from
(
select * from a
union all
select * from b
union all
select * from c
) t

热点排行