SQLSERVER取前10条记录怎样取
单表我会selecttop10fromtableorderbyid联表呢?例如selecttop10from(selectA.name,B.sexfromuserinfo...
单表我会
select top 10 from table order by id
联表呢?
例如
select top 10 from (select A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) order by id
就会报错,请指教 展开
select top 10 from table order by id
联表呢?
例如
select top 10 from (select A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) order by id
就会报错,请指教 展开
展开全部
你这用得着嵌套吗。不是多此一举吗?
select top 10 A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid order by A.id
要是真象你那么写的话,也可以
select top 10 C.name,C.sex from (select A.name name,B.sex sex ,A.id id from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) C order by A.id
select top 10 A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid order by A.id
要是真象你那么写的话,也可以
select top 10 C.name,C.sex from (select A.name name,B.sex sex ,A.id id from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) C order by A.id
展开全部
order by中指定了用id排序,至少子查询中应该包含id列吧?另外子查询用在from子句中必须为子查询设置一个别名。
select top 10 * from (select A.id,A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) as newtable order by id
select top 10 * from (select A.id,A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) as newtable order by id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
思路是正确的,但是sql语句写的有些问题,这么写就对了
select top 10 * from (select A.name,B.sex,A.id from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) C order by C.id
select top 10 * from (select A.name,B.sex,A.id from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) C order by C.id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-01-03 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
oracle:
select * from tab where rownum <= 10;
sql server:
select top 10 * from tab
mysql:
select * from tab limit 10
db2:
select * from tab fetch first 10 rows only
select * from tab where rownum <= 10;
sql server:
select top 10 * from tab
mysql:
select * from tab limit 10
db2:
select * from tab fetch first 10 rows only
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select top 10 A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid order by A.id
也许这样会简单点!
也许这样会简单点!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询