select id,AreaName,AreeaKey,Px into bb from 
(select id,province as AreaName,ordernum AreaKey,id Px from area 
union all 
select id,schoolname,Areaid,ordernum from school) as 表别名

解决方案 »

  1.   

    select id,province as AreaName,ordernum AreaKey,id Px into bb from area
    union all
    select id,schoolname,Areaid,ordernum from school
      

  2.   

    select id,AreaName,AreeaKey,Px into bb from 
    (
    select id,province as AreaName,ordernum AreaKey,id Px from area 
    union all 
    select id,schoolname,Areaid,ordernum,'' from school
    ) tt
      

  3.   

    1,2楼的写法都可以。初学者可以采用1楼的写法,语义明确些。select into union 本来就把union的合集去into的,2楼的写法是直写。
      

  4.   


    --(1)你犯了2个错误一个是使用union all连接2个表的时候,2个表的数量必须一致
    --(2)union all之后组成新的表在查询,表后面要表别名 
      

  5.   

    select id,AreaName,AreeaKey,Px into bb from 
    (
    select id,province as AreaName,ordernum AreaKey,id Px from area 
    union all 
    select id,schoolname,Areaid,ordernum from school
    ) tt
      

  6.   

    好了行了可以结了,我建了2个结构相同的表才union all