现有3个表
a 表示查看记录  b 表示下载记录 c表示邀请记录
要把3个表数据查询出来来整合到一个表里显示  每条记录还得有个状态(查看,下载,邀请),,,,,这个状态每个表里没有字段的  
请高手简单知道下 帮我写个主体框架 

解决方案 »

  1.   


    --如果表结构一样,不一样自己改下成一样的
    select *,'查看' from a
    union all
    select *,'下载' from b
    union all
    select *,'邀请' from c
      

  2.   

    假如三个表的字段都是一样的:select * into newtable from(
    select '查看' as type,* from a
    union all
    select '下载',* from b
    union all
    select '邀请',* from c
    )t
      

  3.   

    select *,'查看' as flag from a
    union all
    select *,'下载' as flag from b
    union all
    select *,'邀请' as flag from c
      

  4.   

    select ...,'查看' as 状态
    from 查看记录
    union all
    select ...,'下载' as 状态
    from 下载记录
    union all
    select ...,'邀请' as 状态
    from 邀请记录
      

  5.   


    select *,'查看' as '状态' from a  --第一次每个列都要加个列名,*里的自己看情况改
    union all
    select *,'下载' from b
    union all
    select *,'邀请' from c
      

  6.   

    ...部分需要字段数相同,对应类型相同,必要的可以用NULL
      

  7.   

    select *,'查看' as 状态 from a
    union all
    select *,'下载' from b
    union all
    select *,'邀请' from c
      

  8.   


    楼主,若你的表的结构相同,可以使用unio all 连接查询:
    select *,'查看' as '状态' from 表名
    union all
    select *,'下载' from 表名
    union all
    select *,'邀请'  from 表名