谢谢楼上的.news
============================
id,classidclass
============================
classid,className无论从哪个表里提取出来最终结果都无所谓,只要提取出来了就ok,要求id反向排序。我先尝试过了distinct关键字,但是使用了之后,排序会乱,很郁闷。
============================
id,classidclass
============================
classid,className无论从哪个表里提取出来最终结果都无所谓,只要提取出来了就ok,要求id反向排序。我先尝试过了distinct关键字,但是使用了之后,排序会乱,很郁闷。
news,class
where news.id=class.classid
order by news.id
就是在()里排序一次,里面一同要包含top 10要不无法排序。
()外在排一次序,disticnt是必须要用的呀。
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
(
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 娱乐