分类表
A
B
C
D
....新闻表
xxx
xxxx
xx
......页面显示A类
xxxx
xxxxB类
xxxx
xxxxC类
xxxx
xxxx
....如次一个分类,N条记录,有没有办法用一调SQL查询来实现这样的数据要求,现在用的方法,每个分类都要查一次新闻表,实在太痛苦了,求高手解决

解决方案 »

  1.   

    查新闻表的时候, left outer join 分类表,然后在程序中分类显示
      

  2.   

    有没有办法用一调SQL查询来实现这样的数据要求
    -->一个SQL语句只能查询出一个结果集。你想要几个结果集给你?
      

  3.   


    create procedure usp_test
    as
    begin
    select * into #temp from 分类表-----------
    select * from 新闻表 inner join #temp...
    where type='A'
    select * from 新闻表 inner join #temp...
    where type='B'
    select * from 新闻表 inner join #temp...
    where type='C'end
      

  4.   

    建议进行表中字段冗余
    新闻表 根据分类的字段进行合并 进行统计 
    select * from 新闻表 where 分类=A 
    union all
    select * from 新闻表 where 分类=B
    union all
    select * from 新闻表 where 分类=C