建立视图:
create view 新闻模式表
as
select * from news_model1
union all
select * from news_model2
union all
select * from news_model3
union all
select * from news_model4
union all
select * from news_model5
union all
select * from news_model6
go
这样你用:select b.news_id,b.news_topic,b.news_neirong from newstable a,新闻模式表 b where a.news_id=b.news_id

解决方案 »

  1.   

    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model1 b where a.news_id=b.news_id and a.[news_showtype]='模式1' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model2 b where a.news_id=b.news_id and a.[news_showtype]='模式2' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model3 b where a.news_id=b.news_id and a.[news_showtype]='模式3' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model4 b where a.news_id=b.news_id and a.[news_showtype]='模式4' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model5 b where a.news_id=b.news_id and a.[news_showtype]='模式5' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model6 b where a.news_id=b.news_id and a.[news_showtype]='模式6' 
      

  2.   

    或修改表结构使用分区视图提高查询速度:
    create table [2002年数据] (编号 int,年 int check(年=2002) default 2002,数据 int,primary key(编号,年))
     
    create table [2003年数据] (编号 int,年 int check(年=2003) default 2003,数据 int,primary key(编号,年))create view 所有数据 as
    select * from [2002年数据] 
    union all
    select * from [2003年数据] 
    go
      

  3.   

    这样不行不行!
    select b.news_id,b.news_topic,b.news_neirong from newstable a,
    (select * from news_model1 
    union select * from new_model2 
    union select * from new_model3 
    union select * from news_model4 
    union select * from news_model5 
    union select * from news_model6) b where a.news_id=b.news_id
      

  4.   

    用union all
    最好建视图,然后直接从视图中查询就好。
      

  5.   

    对不起,可能我没有解释得很清楚,
    现六个新闻模式表中除共有的news_id字段外,它们每个表还各有各的字段,
    如news_model1有news_topic,..;news_model2有news_image,..;news_model3有comany_js,..;...
    想要显示的是,每个新闻相对应的新闻模式表内容
    如果该新闻用的是模式1就把表news_model1内的所有字段news_topic,news_neirong...显示;
    如果该新闻用的是模式2就把表news_model2内的所有字段news_image,news_imagesize...显示;
    如果该新闻用的是模式2就把表news_model3内的所有字段comany_js,comany_gw...显示;
    ...
    如果这样的话好像union就不好使了,有什么好法子呢?
      

  6.   

    更正:
    如果该新闻用的是模式3就把表news_model3内的所有字段comany_js,comany_gw...显示;
    ...
      

  7.   

    这样要两个结果集,只能用两句SQL
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model1 b where a.news_id=b.news_id and a.[news_showtype]='模式1' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model2 b where a.news_id=b.news_id and a.[news_showtype]='模式2' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model4 b where a.news_id=b.news_id and a.[news_showtype]='模式4' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model5 b where a.news_id=b.news_id and a.[news_showtype]='模式5' union
    select b.news_id,b.news_topic,b.news_neirong from newstable a,news_model6 b where a.news_id=b.news_id and a.[news_showtype]='模式6' select b.* from newstable a,news_model3 b where a.news_id=b.news_id and a.[news_showtype]='模式3'