谢谢楼上的.news
============================
id,classidclass
============================
classid,className无论从哪个表里提取出来最终结果都无所谓,只要提取出来了就ok,要求id反向排序。我先尝试过了distinct关键字,但是使用了之后,排序会乱,很郁闷。

解决方案 »

  1.   

    select top 10 news.id,news.classid,class.classname from 
    news,class 
    where news.id=class.classid
    order by news.id
      

  2.   

    先谢谢楼上的,但是仍然不满足要求。我需要news表中classid不重复的前10条记录。而不是要有重复的。
      

  3.   

    如过只是排序混乱,你用一下嵌套语句,在按id排序不就行了吗?
    就是在()里排序一次,里面一同要包含top 10要不无法排序。
    ()外在排一次序,disticnt是必须要用的呀。
      

  4.   

    select top 10 news.id as id,news.classid as classid,class.classname as classname from 
    news a,class 
    where news.classid=class.classid and not exists (select * from news where classid=a.classid and id>a.id) order by id desc
      

  5.   

    一但使用了DISTINCT以后,排序就不对了。我测试过使用内联结来解决。只有通过写一个存储过程来实现,但是我对存储过程的编写不是很熟悉,后来用了个触发器来实现对class表来排序。
      

  6.   

    create table news
    (
      id int identity,classid int
    )create table class
    (
      classid int,className varchar(20)
    )insert news(classid) 
    select 1 union all 
    select 2 union all 
    select 2 union all 
    select 3 union all 
    select 4 union all
    select 4insert class
    select 1,'科技' union 
    select 2,'体育' union
    select 3,'娱乐' union
    select 4,'电影'select * from news--查询结果
    select top 10 A.classid,(select className from class where A.classid=classid) className
    from news A 
    where (select count(*) from news where A.classid=classid)<2 --删除测试数据
    drop table news
    drop table class结果:
    1 科技
    3 娱乐