数据库SQLServer2005分页查询数据:
数据库中有两个表:blog和category;category中id字段为主键,并且为blog表中的外键。现在我想查询:blog中的各个字段的值并且对应category中...
数据库中有两个表:blog和category;category中id字段为主键,并且为blog表中的外键。现在我想查询:blog中的各个字段的值并且对应category中的值!语句如下:
select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog ) 结果如图所示!
但是现在我想把数据按照id 从大到小排列,语句如下:select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog ) order by id desc 但是结果不正确! 展开
select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog ) 结果如图所示!
但是现在我想把数据按照id 从大到小排列,语句如下:select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog ) order by id desc 但是结果不正确! 展开
展开全部
按blog.id排序是:
select top 5 blog.*,category.category from blog,category where blog.catId=category.id order by blog.id desc
按category.id排序是:
select top 5 blog.*,category.category from blog,category where blog.catId=category.id order by category.id desc
select top 5 blog.*,category.category from blog,category where blog.catId=category.id order by blog.id desc
按category.id排序是:
select top 5 blog.*,category.category from blog,category where blog.catId=category.id order by category.id desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select top 0 这个是干什么的,有什么意义吗?
是想按照哪个id排序啊?
select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog order by id desc ) order by id desc
是想按照哪个id排序啊?
select top 5 * from blog ,category where blog.catId=category.id and blog.id not in (select top 0 blog.id from blog order by id desc ) order by id desc
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
order by id desc
这一句的ID不明确,它是属于哪个表的
还有 not in (select top 0 blog.id from blog )这句没有意义
这一句的ID不明确,它是属于哪个表的
还有 not in (select top 0 blog.id from blog )这句没有意义
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT TOP 5 * FROM BLOG LEFT JION CATEGORY ON BLOG.ID = CATEGORY.ID
ORDER BY BLOG.ID DESC;
ORDER BY BLOG.ID DESC;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询